<?php
/*
 * employe/edit.phtml
 */
?>
<?php

use RHX\Helper\RHDateTime;
use RHX\Helper\Number;
use Zend\Debug\Debug;
use RHX\Model\Manager\FileManager;
?>
<?php
$title = 'Fiche Employé';
$this->headTitle($title);
$avenantTable = new \RHX\Model\Table\AvenantTable($fileManager->getAdapter());

// Variables
/**
 * Employé en Cours
 * 
 * @var \RHX\Model\Object\Employe $employe
 */
$employe = $this->employe;
$site	 = $employe->getSite();

$employeHistory	 = $this->employeHistory;
$colleges	 = $this->colleges;

$etatCivil	 = array(0	 => '', 1	 => 'Monsieur', 2	 => 'Madame', 3	 => 'Mademoiselle');
$situation	 = array(
    '0'	 => 'Célibataire',
    '1'	 => 'Célibataire',
    '2'	 => 'Marié(e)',
    '3'	 => 'Divorcé(e)',
    '4'	 => 'Veuf(ve)',
);
$niveau		 = array();
$echelon	 = array();
for ($i = 1; $i < 6; $i++) {
    if ($i < 5) {
	$echelon["$i"] = "Echelon $i";
    }
    $niveau["$i"] = "Niveau " . Number::getRomanNumber($i);
}
?>

<?php 
    $repUpl = $this->repUpl;
    foreach ($repUpl as $k => $v){
        $repUpl[$k] = str_replace('public/', '', $v);
    }
    
?>

<?php 
    $isTranfered = $employe->isTransfered() 
?>
<div class="content-head">
    <?php $name		 = (is_null($employe->nom2) || ($employe->nom2 == '')) ? $employe->nom1 : $employe->nom2; ?>
    <?php $infoEmploye = "<span id='title-employe-prenom'>". $employe->prenom . "</span>" ;
          $infoEmploye .= "  <span id='title-employe-nom'>" .$name . "</span>" ;
          $infoEmploye .= ' - '.$site->libelle;            
     ?>
    <h3><?php echo $title; ?> : <?php echo $infoEmploye ;?> </h3>
    <div class="toolbar">        
        <button class='btn btn-inverse' onclick="location.href = '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'index', 'id'		 => $site->id, 'other1'	 => 1)) ?>';">Revenir à la liste des employés du Site</button>
    </div>
</div>
<div class="content-body empl-border">
    <div class="empl-full bleu empl-title">Etat Civil : <a href="#" id="etatcivil" data-name="civil_id" data-pk="<?php echo $employe->matricule; ?>" data-type="select"><?php echo $etatCivil[(int) $employe->civil_id] ?></a></div>

    <div class="empl-top">
        <div class="empl-matricule saumon empl-title">Matricule : <?php echo $employe->getMatricule(true); ?></div>
        <div class="empl-site marron empl-title">
            Site Employeur : <a href="#" id="site_" onclick='return false;' data-name="site_id" data-pk="<?php echo $employe->matricule; ?>" data-type="select"><?php echo $site->libelle; ?></a>
	    
             <?php if(! $isTranfered ) : ?>
                <button class="btn btn-info btn-small" id="changeSite" style="float: right; text-transform: none; margin-right: 4px;">Changer de Site</button>
            <?php else : ?>
                <button class="btn  btn-small" id="cancelChangeSite" style="float: right; text-transform: none; margin-right: 4px;">Annuler le transfert</button>
                <span class='employe-info-tranfert' >
                    <span class='' style="color: white;"><!--Employé -->Transferé au site </span>
                    <?php $siteDest = $employe->getDestinationSite(); ?>
                    <?php if($siteDest) :?>
                        "<?php echo $siteDest->libelle ;?>"
                    <?php endif; ?>
                </span>
            <?php endif; ?>
        </div>
    </div>

    <div class="empl-left">
        <div class="empl-group">
            <div class="empl-photo"  id="btn-uploadPhoto-cntr" >
                <a href="#" id="btn-uploadPhoto" data-id="<?php echo $employe->matricule; ?>"  class='btn btn-info btn-small' style="display:none; z-index:55555;">
		    Télécharger photo
		</a>
		<a href="#" id="photo-upload" data-id="<?php echo $employe->matricule; ?>"  style="width: 100%; height: 100%; ">
		    <?php $basePath	 = str_replace('public', '', $this->basePath()); ?>
		    <?php $photo		 = ($employe->photo == '' || $employe->photo == '#') ? $this->basePath() . '/img/rhx/user-192x200.png' : $this->basePath() . '/'. $repUpl['photo'] . $employe->photo; ?>
		    <img id="photo" src="<?php echo $photo; ?>" width="200" height="250">
		</a>
	    </div>
            <!--div class="empl-full violet" style="text-align: center;">
                <?php $hasCv  = $employe->cv_path && $employe->cv_path != '' && $employe->cv_path != '#' ; ?>                
		Curriculum Vitae<br>
                <a href="<?php echo $this->basePath() .'/'. $repUpl['cv'] .$employe->cv_path ?>" id="cv_link" class="btn btn-success btn-small" style='<?php echo !$hasCv ? 'display:none;' : '';?> ' target='_blank' >Voir</a> 
                 
                <a href="#" class="btn btn-info btn-small" id="cv-upload" data-pk="<?php echo $employe->matricule; ?>"><?php echo $hasCv ? 'Changer':  'Télécharger' ;?></a>
	    </div-->
             <div class='empl-full violet' style="text-align: center;" >                    
                    Curriculum Vitae<br>
                    <?php $flagFile  = FileManager::EMPLOYE_CV_FILE ;
                          $fileManager->setFlag($flagFile);
                    ?>
                    
                    <?php $hasFile  = $employe->$flagFile && $employe->$flagFile != '' && $employe->$flagFile != '#' ;?>      
                    
                    <?php $idLinkFile          = $fileManager->getFlag(). '_link' ;
                          $idBtnUplFile= $fileManager->getFlag() . '-upload'; 
                          $repertory = str_replace('public/', '', $fileManager->getUploadDirectory());    
                    ?>
                                        
                    <a href="<?php echo $this->basePath() . '/'.  $repertory . $employe->$flagFile ; ?>" id="<?php echo $idLinkFile; ?>" class="btn btn-success btn-small" style='<?php echo !$hasFile ? 'display:none;' : '';?> ' target='_blank'>Voir</a>                
                    <a href="#" id="<?php echo $idBtnUplFile ; ?>" data-id="<?php echo $employe->matricule; ?>" class="btn btn-info btn-small"><?php echo $hasFile ? 'Changer':  'Télécharger' ;?></a>
                </div>
            
            <div class="empl-full saumon" style="text-align: center;">
		Code Caisse TC POS<br>
		<a href="#" id="code_caisse" data-type="text" data-pk="<?php echo $employe->matricule; ?>" data-name="code_caisse_tcpos"><?php echo $employe->code_caisse_tcpos; ?></a>
	    </div>
	    <!--	    <div class="empl-full gris" style="text-align: center;">
			    <a href="<?php echo $this->url('RHX/default', array('controller'	 => 'export', 'action'	 => 'ficheEmploye')) ?>">Exporter en Word</a>
			</div>-->
            <?php if ($hrModulee['is_labo'] ):?>            
                <div style="margin-top: 15px ; text-align: center;" class="empl-full bleu">Heures Modulées : <span> <?php echo $hrModulee['value'];?></span></div>            
            <?php endif;?>
        </div>
        
    </div>

    <div class="empl-center">

        <div class='empl-group'>
            <div class='empl-full saumon2'>
                Nom d'usage : <a href="#" id="nom" class='uppercase' data-name="nom1" data-pk="<?php echo $employe->matricule; ?>" data-type="text"><?php echo $employe->nom1 ?></a>
            </div>
            <div class='empl-full saumon2'>
                Nom de jeune Fille : <a href="#" id="nom2" class='uppercase' data-name="nom2" data-pk="<?php echo $employe->matricule; ?>" data-type="text"><?php echo $employe->nom2 ?></a>
            </div>
            <div class='empl-full saumon2'>
                Prénom : <a href="#" id="prenom" class='capitalize' data-name="prenom" data-pk="<?php echo $employe->matricule; ?>" data-type="text"><?php echo $employe->prenom ?></a>
            </div>
        </div>

        <div class="empl-group">
            <div class="empl-full gris">Adresse 1 : <a href="#" id="adresse1" data-name="adresse1" data-pk="<?php echo $employe->matricule; ?>" data-type="text"><?php echo $employe->adresse1 ?></a></div>
            <div class="empl-half gris">CP : <a href="#" id="cp1" data-name="cp1" data-pk="<?php echo $employe->matricule; ?>" data-type="text"><?php echo $employe->cp1 ?></a></div>
            <div class="empl-half gris">Ville : <a href="#" id="ville1" data-name="ville1" data-pk="<?php echo $employe->matricule; ?>" data-type="text"><?php echo $employe->ville1 ?></a></div>
            <div class="empl-full gris">Adresse 2 : <a href="#" id="adresse2" data-name="adresse2" data-pk="<?php echo $employe->matricule; ?>" data-type="text"><?php echo $employe->adresse2 ?></a></div>
            <div class="empl-half gris">CP : <a href="#" id="cp2" data-name="cp2" data-pk="<?php echo $employe->matricule; ?>" data-type="text"><?php echo $employe->cp2 ?></a></div>
            <div class="empl-half gris">Ville : <a href="#" id="ville2" data-name="ville2" data-pk="<?php echo $employe->matricule; ?>" data-type="text"><?php echo $employe->ville2 ?></a></div>
            <div class="empl-half gris">Téléphone : <a href="#" id="num_mobile" data-name="telephone" data-pk="<?php echo $employe->matricule; ?>" data-type="text"><?php echo $employe->telephone ?></a></div>
            <div class="empl-half gris">E-mail : <a href="#" id="email" data-name="email" data-pk="<?php echo $employe->matricule; ?>" data-type="text"><?php echo $employe->email ?></a></div>
        </div>

        <div class="empl-group">
            <div class="empl-full beige">
                Numéro d'immatriculation CPAM : <a href="#" id="num_cpam" data-name="cpam" data-pk="<?php echo $employe->matricule; ?>" data-type="text"><?php echo $employe->cpam ?></a>
            </div>
            <div class="empl-full beige">
                Situation Familiale : <a href="#" id="situation_familiale" data-name="situation_id" data-pk="<?php echo $employe->matricule; ?>" data-type="select"><?php echo $situation[$employe->situation_id]; ?></a>
            </div>
            <div class="empl-full beige">
                Nombre d'enfant : <a href="#" id="nombre_enfant" data-name="enfant" data-pk="<?php echo $employe->matricule; ?>" data-type="text"><?php echo $employe->enfant ?></a>
            </div>
            <div class="empl-full beige">
                Numéro d'immatriculation Pole Emploi : <a href="#" id="num_pole_emploi" data-name="pole_emploi" data-pk="<?php echo $employe->matricule; ?>" data-type="text"><?php echo $employe->pole_emploi ?></a>
            </div>
        </div>

        <div class='empl-group'>
	    <?php
	    $transport	 = $employe->getTransport();
	    $mutuelle	 = $employe->getMutuelle();
	    ?>
            <div class='empl-half gris'>
                Mutuelle : <a href="#" id="mutuelle" data-name="mutuelle" data-pk="<?php echo $employe->matricule; ?>" data-type="select"><?php echo $mutuelle->libelle; ?></a>
            </div>
            <div class='empl-half gris-beige'>
                Titre Transport : <a href="#" id="titre_transport" data-name="transport_id" data-pk="<?php echo $employe->matricule; ?>" data-type="select"><?php echo $transport->libelle; ?></a>
            </div>
            <div class='empl-half gris'>
		<?php $dateEffet	 = new \DateTime($employe->mutuelle_date_effet); ?>
                Date d'effet : <a href="#" class="rhdatetime" id="date_effet" data-name="mutuelle_date_effet" data-pk="<?php echo $employe->matricule; ?>" data-type="combodate"><?php echo $dateEffet->format('d/m/Y'); ?></a>
		<div class="cancel-icon">
		    <a href="#" class="cancel-date" data-id="date_effet" data-name="mutuelle_date_effet" data-pk="<?php echo $employe->matricule; ?>" title="Effacer la Date">
			<img src="<?php echo $this->basePath() . '/img/rhx/close-12x12.png' ?>" title="Effacer la date">
		    </a>
		</div>
            </div>
            <div class='empl-half gris-beige'>
                Véhicule de fonction : <a href="#" id="vehicule_fonction" data-type='text' data-name='vehicule' data-pk='<?php echo $employe->matricule ?>'><?php echo $employe->vehicule; ?></a>
            </div>
            <div class='empl-half' style='border: none; margin-right: 2px'></div>
            <div class='empl-half gris-beige'>
                Immatriculation du véhicule : <a href="#" id="immatriculation" data-type="text" data-name='immatriculation' data-pk='<?php echo $employe->matricule ?>'><?php echo $employe->immatriculation ?></a>
            </div>
	    <?php
	    $visite		 = $employe->getVisiteMedicale();
	    $dateVisite	 = new \DateTime($visite->date_visite);
	    ?>
            <div class='empl-half gris'>
                Date visite médicale : <a class="rhdatetime" href="#" id="date_visite" data-pk="<?php echo $visite->id; ?>" data-name="date_visite" data-type="combodate"><?php echo $dateVisite->format('d/m/Y'); ?></a>
		<div class="cancel-icon">
		    <a href="#" class="cancel-date" data-id="date_visite" data-table="rh_employe_sante" data-name="date_visite" data-pk="<?php echo $visite->id; ?>" title="Effacer la Date">
			<img src="<?php echo $this->basePath() . '/img/rhx/close-12x12.png' ?>" title="Effacer la date">
		    </a>
		</div>
            </div>
            <div class='empl-half gris-beige'>
                Numéro de permis : <a href="#" id="num_permis" data-type="text" data-name='num_permis' data-pk='<?php echo $employe->matricule ?>'><?php echo $employe->num_permis; ?></a>
            </div>
        </div>
    </div>
    <div class="empl-right">

        <div class='empl-group'>
            <div class='empl-full gris-beige'>
		<?php $dateNaissance	 = new \DateTime($employe->naissance); ?>
                Date de naissance : <a class="rhdatetime" href="#" id='date_naissance' data-pk="<?php echo $employe->matricule ?>" data-name="naissance" data-type="combodate"><?php echo $dateNaissance->format("d/m/Y"); ?></a>
		<div class="cancel-icon">
		    <a href="#" class="cancel-date" data-id="date_naissance" data-name="naissance" data-pk="<?php echo $employe->matricule ?>" title="Effacer la Date">
			<img src="<?php echo $this->basePath() . '/img/rhx/close-12x12.png' ?>" title="Effacer la date">
		    </a>
		</div>
            </div>
            <div class='empl-full gris-beige'>
                Lieu de naissance : <a href="#" id="lieu_naissance" data-name="naissance_lieu" data-pk="<?php echo $employe->matricule; ?>" data-type="textarea"><?php echo $employe->naissance_lieu ?></a>
            </div>
            <div class='empl-full gris-beige'>
                Pays de naissance : <a href="#" id="pays_naissance" data-name="naissance_pays" data-pk="<?php echo $employe->matricule; ?>" data-type="text"><?php echo $employe->naissance_pays ?></a>
            </div>
            <div class='empl-full gris-beige'>
		<?php $nationalite	 = $employe->getNationalite(); ?>
                Nationalité : <a href="#" id="nationalite" data-type="select" data-name='nationalite_id' data-pk='<?php echo $employe->matricule; ?>'><?php echo ucfirst($nationalite->libelle); ?></a>
            </div>
        </div>

        <div class='empl-group'>
	    <?php
	    $titreSejour	 = $employe->getTitreSejour();
	    ?>
            <div class='empl-full saumon'>
                Type Titre de Séjour : <a href="#" id="titre_sejour" data-name="sejour_id" data-pk="<?php echo $employe->matricule; ?>" data-type="select"><?php echo $titreSejour->libelle; ?></a>
            </div>
            
            <div class='empl-full saumon' >                    
                    N° Titre de Séjour :  <a href='#' id="num_titre_sejour" data-name='sejour_num' data-pk="<?php echo $employe->matricule; ?>" data-type='text'> <?php echo $employe->sejour_num;?></a>
                    
                    <div style='margin: 4px 4px; text-align: center;'>
                        <?php $flagFile  = FileManager::EMPLOYE_SEJOUR_NUM_FILE ;
                              $fileManager->setFlag($flagFile);
                        ?>

                        <?php $hasFile  = $employe->$flagFile && $employe->$flagFile != '' && $employe->$flagFile != '#' ;?>      

                        <?php $idLinkFile          = $fileManager->getFlag(). '_link' ;
                              $idBtnUplFile= $fileManager->getFlag() . '-upload'; 
                              $repertory = str_replace('public/', '', $fileManager->getUploadDirectory());    
                        ?>

                        <a href="<?php echo $this->basePath() . '/'.  $repertory . $employe->$flagFile ; ?>" id="<?php echo $idLinkFile; ?>" class="btn btn-success btn-small" style='<?php echo !$hasFile ? 'display:none;' : '';?> ' target='_blank'>Voir</a>                
                        <a href="#" id="<?php echo $idBtnUplFile ; ?>" data-id="<?php echo $employe->matricule; ?>" class="btn btn-info btn-small"><?php echo $hasFile ? 'Changer':  'Télécharger' ;?></a>
                    </div>
                </div>
            
            <div class='empl-full saumon'>
		<?php $finSejour	 = new \DateTime($employe->sejour_fin); ?>
                Fin de validité Titre Séjour : <a class="rhdatetime" href="#" id="date_fin_validite_sejour" data-name="sejour_fin" data-pk="<?php echo $employe->matricule; ?>" data-type="combodate"><?php echo $finSejour->format('d/m/Y'); ?></a>
		<div class="cancel-icon">
		    <a href="#" class="cancel-date" data-id="date_fin_validite_sejour" data-name="sejour_fin" data-pk="<?php echo $employe->matricule ?>" title="Effacer la Date">
			<img src="<?php echo $this->basePath() . '/img/rhx/close-12x12.png' ?>" title="Effacer la date">
		    </a>
		</div>
            </div>
        </div>
        <!-- CHAMPS RIB -->
        
        <div class='empl-group'>
            <div class="empl-full bleu-2" style="color: whitesmoke; text-transform: uppercase; text-align: center;">RIB</div>
            
            <div class='empl-full gris-beige'>
                IBAN : <a href="#" id="rib_iban" data-name="rib_iban" data-pk="<?php echo $employe->matricule; ?>" data-type="text"><?php echo $employe->rib_iban ?></a>
            </div>
            <div class='empl-full gris-beige'>
                BIC : <a href="#" id="rib_bic" data-name="rib_bic" data-pk="<?php echo $employe->matricule; ?>" data-type="text"><?php echo $employe->rib_bic ?></a>
            </div>
            <!--div class='empl-full'>
		Fichier RIB :
                <?php //$hasRib  = $employe->rib && $employe->rib != '' && $employe->rib != '#' ;?>                                
                <a href="<?php //echo $this->basePath() . '/'. $repUpl['rib']  . $employe->rib ; ?>" id="rib_link" class="btn btn-success btn-small" style='<?php //echo !$hasRib ? 'display:none;' : '';?> ' target='_blank'>Voir</a>                
		<a href="#" id="rib-upload" data-id="<?php //echo $employe->matricule; ?>" class="btn btn-info btn-small"><?php //echo $hasRib ? 'Changer':  'Télécharger' ;?></a>
            </div-->
            <div class='empl-full' >                    
                    Fichier RIB: 
                    <?php $flagFile  = FileManager::EMPLOYE_RIB_FILE ;
                          $fileManager->setFlag($flagFile);
                    ?>
                    
                    <?php $hasFile  = $employe->$flagFile && $employe->$flagFile != '' && $employe->$flagFile != '#' ;?>      
                    
                    <?php $idLinkFile          = $fileManager->getFlag(). '_link' ;
                          $idBtnUplFile= $fileManager->getFlag() . '-upload'; 
                          $repertory = str_replace('public/', '', $fileManager->getUploadDirectory());    
                    ?>
                                        
                    <a href="<?php echo $this->basePath() . '/'.  $repertory . $employe->$flagFile ; ?>" id="<?php echo $idLinkFile; ?>" class="btn btn-success btn-small" style='<?php echo !$hasFile ? 'display:none;' : '';?> ' target='_blank'>Voir</a>                
                    <a href="#" id="<?php echo $idBtnUplFile ; ?>" data-id="<?php echo $employe->matricule; ?>" class="btn btn-info btn-small"><?php echo $hasFile ? 'Changer':  'Télécharger' ;?></a>
                </div>
            
        </div>

	<!-- DIPLOMES ET FORMATIONS -->
        <div class='empl-group'>
	    <!-- DIPLOMES -->
	    <!--<div id="diplomes">-->
	    <?php
	    $diplomes	 = $employe->getDiplomes();
	    $count		 = 0;
	    if (is_array($diplomes)) {
		$count = count($diplomes);
	    }
	    else {
		try {
		    $count = $diplomes->count();
		}
		catch (\Exception $ex) {
		    $count = 0;
		}
	    }
	    ?>
	    <div class="empl-full bleu-navy" style="color: whitesmoke; text-transform: uppercase; text-align: center;">Diplômes</div>
	    <div id="diplomes">
		<?php if ($count != 0): ?>
		    <?php foreach ($diplomes as $d): ?>
			<?php $diplom = $d->getDiplome(); ?>
			<div  style='position: relative'>
			    <div class='empl-full violet' id="d<?php echo $d->id; ?>"><?php echo $diplom->libelle; ?></div>
			    <div class="cancel-icon">
				<a href="#" class="cancel-diplome" data-pk="<?php echo $d->id; ?>" title="Effacer le Diplôme">
				    <img src="<?php echo $this->basePath() . '/img/rhx/close-12x12.png' ?>" title="Effacer le Diplôme">
				</a>
			    </div>
			</div>
		    <?php endforeach; ?>
		<?php else: ?>
    		<div id="diplome-none" class='empl-full violet'>Aucun Diplôme</div>
		<?php endif; ?>
	    </div>
	    <!--	    </div>-->
	    <div class="empl-full">&nbsp;<button class="btn btn-info add-diplome" style="float: right;">Ajouter un Diplôme</button></div>
	    <!-- FORMATIONS -->
	    <!--<div id="formations">-->
	    <?php
	    $formations	 = $employe->getFormations();
	    $counter	 = 0;
	    if (is_array($formations)) {
		$counter = count($formations);
	    }
	    else {
		try {
		    $counter = $formations->count();
		}
		catch (\Exception $ex) {
		    $counter = 0;
		}
	    }
	    ?>
	    <div class="empl-full bleu-navy" style="color: whitesmoke; text-transform: uppercase; text-align: center;">Formations</div>
	    <div id="formations-list">
		<?php if ($counter != 0): ?>

		    <?php foreach ($formations as $f): ?>
			<?php $form = $f->getFormation(); ?>
			<div  style='position: relative'>
			    <div class='empl-full vert-olive' id="f<?php echo $f->id; ?>"><?php echo $form->libelle; ?></div>
			    <div class="cancel-icon">
				<a href="#" class="cancel-formation" data-pk="<?php echo $f->id; ?>" title="Effacer la Formation">
				    <img src="<?php echo $this->basePath() . '/img/rhx/close-12x12.png' ?>" title="Effacer la Formation">
				</a>
			    </div>
			</div>
			<!--div class='empl-full vert-olive' id="f<?php echo $form->id; ?>"><?php echo $form->libelle; ?></div-->
		    <?php endforeach; ?>

		<?php else: ?>
    		<div id="formation-none" class='empl-full vert-olive'>Aucune Formation Continue</div>
		<?php endif; ?>
	    </div>
	    <!--</div>-->
	    <div class="empl-full">&nbsp;<button class="btn btn-success add-formation" style="float: right;">Ajouter une Formation</button></div>
        </div>

    </div>

    <div style="clear: both"></div>

    <div class="content-head">
        <h3>&nbsp;</h3>
        <div class="toolbar">
            <!--<button class='btn btn-primary' style='margin-right: 10px;' onclick="save();">Enregistrer</button>-->
            <button class='btn btn-inverse' onclick="location.href = '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'index', 'id'		 => $employe->site_id, 'other1'	 => 1)) ?>';">Revenir à la liste des employés</button>
        </div>
    </div>

</div>

<!-- Contrat -->
<?php
// Type de contrat
$contratType	 = $employe->getContratType();
?>
<?php 
    $isCDI		 = in_array($employe->contrat_type, array(0, 1)); 
    $isActive = (boolean)$employe->actif;
    $isCdiAndActive = $isCDI &&   $isActive ;
    $hasDateDepart = $employe->contrat_fin !=null && $employe->contrat_fin !== '' && $employe->contrat_fin !== '0000-00-00';
    $isCdiAndHasntDateDepart = $isCDI && !$hasDateDepart;
    $isCdiAndHasDateDepart = $isCDI && $hasDateDepart;            
?>

<div class="content-body empl-border">
    <div class="empl-full bleu empl-title">
	<span style="line-height: 32px;">Contrat</span>
	<!--button class="btn btn-primary btn-small" id="doc-printer" style="margin-left: 10px;"><i class="icon icon-white icon-print"></i>&nbsp;&nbsp;Imprimer le Contrat&nbsp;&nbsp;<i class="icon icon-white icon-print"></i></button-->
       
        
	<div style="float: right; margin-right: 10px; position: relative;  opacity:<?php echo $isCdiAndHasDateDepart?  '0.5': '1';?>;">
	    <a href="#" title="<?php echo $isCdiAndHasDateDepart?  '': 'Ajouter un contrat';?>" class="contrat-add" data-matricule="<?php echo $employe->matricule; ?>">
		<img src="<?php echo $this->basePath() . '/img/rhx/add-32x32.png' ?>">
	    </a>
	    <div class="add-contrat" id="dialog-contrat" style="display: none;">
		<!-- -->
	    </div>
	</div>
        
    </div>

    <div class="empl-full saumon2 empl-title" style="margin-top: 15px;">
        Type de contrat : <a href="#" id="contrat_type" data-name="contrat_type" data-pk="<?php echo $employe->matricule; ?>" data-type="select"><?php echo $contratType->libelle; ?></a>
        <form id='contratTypeEditForm' style=display:none;'>            
            <input type="hidden" id='data-contrat_type' name="data-contrat_type" value="<?php echo $employe->contrat_type; ?>">
            <input type="hidden" id='data-employe_active' name="data-employe_active" value="<?php echo $employe->actif; ?>">            
        </form>    
    </div>
    
    <div class=''>
        <div class="empl-left" style="width: 50%">

            <div class='empl-group'>
                <div class="empl-full">
                    <?php $contratDebut	 = new \DateTime($employe->contrat_debut); ?>
                    Date d'entrée : <a class="rhdatetime" href='#' id='debut_contrat' data-name="contrat_debut" data-pk="<?php echo $employe->matricule; ?>" data-type='combodate'><?php echo $contratDebut->format('d/m/Y'); ?></a>
                    <div class="cancel-icon">
                        <a href="#" class="cancel-date" data-id="debut_contrat" data-name="contrat_debut" data-pk="<?php echo $employe->matricule ?>" title="Effacer la Date">
                            <img src="<?php echo $this->basePath() . '/img/rhx/close-12x12.png' ?>" title="Effacer la date">
                        </a>
                    </div>
                </div>
                <?php
                $entretien	 = $employe->getEntretien();
                $withEntretien	 = true;
                if ($entretien->date_entretien == '0000-00-00') {
                    $withEntretien = false;
                }
                $dateEntretien	 = new \DateTime($entretien->date_entretien);
                ?>
                <div class="empl-full">
                    Date dernier entretien individuel : <a href='#' id='entretien' data-name='date_entretien' data-pk='<?php echo $entretien->id; ?>' data-type='combodate'><?php echo ($withEntretien) ? $dateEntretien->format('d/m/Y') : 'Aucun'; ?></a>
                    <div class="cancel-icon">
                        <a href="#" class="cancel-date" data-id="entretien" data-name="date_entretien" data-table="rh_employe_entretien" data-pk="<?php echo $entretien->id; ?>" title="Effacer la Date">
                            <img src="<?php echo $this->basePath() . '/img/rhx/close-12x12.png' ?>" title="Effacer la date">
                        </a>
                    </div>
                </div>
            </div>

        </div>

        <div class="empl-right" style="width: 49%">	
            <div class='empl-group'>

                <a id='btn-rupture-contrat' href='javascript:void(0);' class='btn btn-info'  data-pk="<?php echo $employe->matricule; ?>" style='display: <?php echo !( $isCdiAndHasntDateDepart) ? 'none' : '' ?>;' >Rupture de contrat</a>

                <div class='empl-full gris' style='display: <?php echo $isCdiAndHasntDateDepart ? 'none' : '' ?>;'>
                    <?php $dateDepart	 = new \DateTime($employe->contrat_fin); ?>
                    Date départ : <a class="rhdatetime" href='#' id='fin_contrat' data-name="contrat_fin" data-pk="<?php echo $employe->matricule; ?>" data-type='combodate'><?php echo $dateDepart->format('d/m/Y'); ?></a>
                    <?php //if($isCdiAndHasDateDepart): ?>
                    <?php //else: ?>
                    <div class="cancel-icon">
                        <a href="#" class="cancel-date" data-id="fin_contrat" data-name="contrat_fin" data-pk="<?php echo $employe->matricule ?>" title="Effacer la Date">
                            <img src="<?php echo $this->basePath() . '/img/rhx/close-12x12.png' ?>" title="Effacer la date">
                        </a>
                    </div>
                    <?php //endif; ?>
                </div>
                <div class='empl-full gris' style='display: <?php echo $isCdiAndHasntDateDepart ? 'none' : '' ?>;' >
                    <?php $motif		 = $employe->getMotif(); ?>
                    Motif départ : <a href='#' id='depart_motif' data-type='select' data-name="contrat_motif_depart" data-pk="<?php echo $employe->matricule; ?>"><?php echo $motif->libelle; ?></a>
                </div>
                <a id='btn-rupture-contrat-cancel' href='javascript:void(0);' class='btn-rupture-contrat-cancel btn btn-info btn-small'  data-pk="<?php echo $employe->matricule; ?>" style='display: <?php echo  ($isCdiAndHasntDateDepart) ? 'none' : '' ?>;'>Annuler la rupture</a>

            </div>
        </div>
    </div>
    <div class='clear-auto'></div>
    <div>
        <div class="empl-left" style="width: 50%; margin: 4px 0;">
            <div class='empl-group'style='margin-bottom: 10px; margin-top: -10px;'>
                <div class='empl-full gris' >                    
                    Pièce jointe : 
                    <?php $flagContratFile  = FileManager::EMPLOYE_CONTRAT_FILE ;
                          $fileManager->setFlag($flagContratFile);
                    ?>
                    
                    <?php $hasFileContrat  = $employe->$flagContratFile && $employe->$flagContratFile != '' && $employe->$flagContratFile != '#' ;?>                
                    
                    <?php $idLinkContrat          = $fileManager->getFlag(). '_link' ;
                          $idBtnUplContrat = $fileManager->getFlag() . '-upload'; 
                          $repertory = str_replace('public/', '', $fileManager->getUploadDirectory());    
                    ?>
                                        
                    <a href="<?php echo $this->basePath() . '/'.  $repertory . $employe->$flagContratFile ; ?>" id="<?php echo $idLinkContrat; ?>" class="btn btn-success btn-small" style='<?php echo !$hasFileContrat ? 'display:none;' : '';?> ' target='_blank'>Voir</a>                
                    <a href="#" id="<?php echo $idBtnUplContrat ; ?>" data-id="<?php echo $employe->matricule; ?>" class="btn btn-info btn-small"><?php echo $hasFileContrat ? 'Changer':  'Télécharger' ;?></a>
                </div>
            </div>

        </div>
         <div class="empl-right" style="width: 49%">            

        </div>
    </div>   
    

    <!-- Avenant -->
    <?php
    $avenant	 = $employe->getAvenant();
    
    $poste		 = $employe->getPoste();
    ?>
    <div class="empl-full bleu empl-title">
        <span style='line-height: 20px'>
            <span title="<?php echo $avenant->id; ?>">Avenants</span> &nbsp;
            <div class="toolbox">
                <!--<a href="#" id="avenantNewButton" onclick="return addAvenant();">
                    <img src="<?php echo $this->basePath() . '/img/foam/add.png' ?>" alt="Ajouter un Avenant" title="Ajouter un nouvel Avenant">
                </a>&nbsp;-->
                
		
		<a href="#" class=" btn btn-danger btn-small hide" id="avenantCancelButton" onclick="return cancelAvenantChange();">
		    Annuler l'ajout &nbsp;<i class="icon-white icon-folder-close"></i>
		    <!--<img src="<?php echo $this->basePath() . '/img/rhx/cancel-32x32.png' ?>" alt="Editer l'avenant" title="Fermer l'édition en cours">-->
		</a>&nbsp;&nbsp;
		<a href='#' id='save-planning' class='btn btn-success btn-small hide'>Créer le Nouvel Avenant&nbsp;&nbsp;<i class='icon-white icon-plus-sign'></i></a>
            </div>
        </span>
	<span style="line-height: 20px; margin-left: 50px; font-size: 1.5em; color: #ffffff;" id="avenant-name"></span>
    </div>

    <div class="empl-left empl-highlight" style="width: 50%">

	<!-- EDITION AVENANT -->
        <div class="empl-group" id="posteEdit">
            <div class="empl-full empl-saumon">
                Poste : <a href='#' id='poste' data-name="poste_id" data-pk="<?php echo $avenant->id ?>" data-type='select' onclick='return false;'><?php echo $poste->libelle ?></a>
            </div>
	    <?php
	    $college = new \RHX\Model\Object\College();
	    if ($avenant) {
		$college = $avenant->getCollege();
	    }
	    ?>
            <div class="empl-full empl-saumon">
                Collège : <a href='#' id='college' data-type='select' data-pk="<?php echo $avenant->id ?>" data-name="college"><?php echo $college->libelle; ?></a>
            </div>
            <div class="empl-full empl-saumon">
                Niveau : <a href='#' id='niveau' data-type='select' data-pk="<?php echo $avenant->id ?>" data-name="niveau">Niveau <?php echo Number::getRomanNumber($avenant->niveau); ?></a>
            </div>
            <div class="empl-full empl-saumon">
                Echelon : <a href='#' id='echelon' data-type='select' data-pk="<?php echo $avenant->id ?>" data-name="echelon">Echelon <?php echo $avenant->echelon ?></a>
            </div>
            
            
            <?php    if (! $avenant->isAvenantInitiale()) : ?>                 
                <div class='empl-full empl-saumon' >                    
                    Pièce jointe : 
                    <?php $flagFile  = FileManager::EMPLOYE_AVENANT_FILE ;
                          $fileManager->setFlag($flagFile);
                    ?>                
                    <?php $hasFile  = $avenant->$flagFile && $avenant->$flagFile != '' && $avenant->$flagFile != '#' ;?>                

                    <?php $idLinkFile          = $fileManager->getFlag(). '_link' ;
                          $idBtnUplFile = $fileManager->getFlag() . '-upload'; 
                          $repertory = str_replace('public/', '', $fileManager->getUploadDirectory());    
                    ?>
                    <?php if(! $hasFile) : ?>
                        <span id='<?php echo $flagFile; ?>-info-hasFile'>Aucun</span>
                    <?php endif ; ?>

                    <a href="<?php echo $this->basePath() . '/'.  $repertory . $avenant->$flagFile ; ?>" id="<?php echo $idLinkFile; ?>" class="btn btn-success btn-small" style='<?php echo !$hasFile ? 'display:none;' : '';?> ' target='_blank'>Voir</a>                
                    <a href="#" id="<?php echo $idBtnUplFile ; ?>" data-id="<?php echo $avenant->id; ?>" class="btn btn-info btn-small" style='display:none;'><?php echo $hasFile ? 'Changer':  'Télécharger' ;?></a>
                </div>
                 
             <?php    else : ?>

             <?php    endif ; ?>
        </div>
        
	<!-- NOUVELLE AVENANT POSTE -->
	<div class="empl-group" id="posteNew" style="display: none;">
            <div class="empl-full empl-saumon">
                Poste : <a href='#' id='posteNeo' data-type='select' onclick='return false;'><?php //echo $poste->libelle    ?></a>
            </div>
            <div class="empl-full empl-saumon">
                Collège : <a href='#' id='collegeNeo' data-type='select' onclick='return false;'><?php //echo $college->libelle;    ?></a>
            </div>
            <div class="empl-full empl-saumon">
                Niveau : <a href='#' id='niveauNeo' data-type='select' onclick='return false;'></a>
            </div>
            <div class="empl-full empl-saumon">
                Echelon : <a href='#' id='echelonNeo' data-type='select' onclick='return false;'></a>
            </div>
            
            <div class='empl-full empl-saumon' >                    
                Pièce jointe : 
                <?php $flagFile  = FileManager::EMPLOYE_AVENANT_FILE ;
                      $fileManager->setFlag($flagFile);
                ?>

                <?php $idLinkFile          = $fileManager->getFlag(). '_libelle-adding' ;
                      $idBtnUplFile = $fileManager->getFlag() . '-upload-adding'; 
                      $repertory = str_replace('public/', '', $fileManager->getUploadDirectory());    
                ?>
                
                <span id='<?php echo $idLinkFile; ?>'></span>                
                <a href="#" id="<?php echo $idBtnUplFile ; ?>" data-id="0" class="btn btn-info btn-small" >Télécharger</a>
            </div>
        </div>
    </div>

    <div class="empl-right empl-highlight" style="width: 49%">
        <div class="empl-group" id="avenantEdit">
            <form id='avenantEditForm' style=display:none;'>                        
                <input type="hidden" id='data-avenant_encours' name="data-avenant_encours" value="<?php echo $avenant->id ?>">            
            </form>  
            <div class="empl-full empl-jaune">
                Contrat horaire hebdomadaire : <a href='#' id='horaire_hebdo' data-name="hebdo" data-pk="<?php echo $avenant->id; ?>" data-type='text' onclick='return false;'><?php echo $avenant->hebdo ?></a> heures
            </div>
            <div class="empl-full empl-jaune">
                Taux horaire : <a href='#' id='horaire_taux' data-name="taux" data-pk="<?php echo $avenant->id; ?>"  data-type='text' onclick='return false;'><?php echo $avenant->taux ?></a> €
            </div>
            <div class="empl-full empl-gris">
		<?php $debutAvenant	 = new \DateTime($avenant->debut); ?>
                Début : 
                <!--a href="#" id="avenant_debut" data-name="debut" data-pk="<?php echo $avenant->id; ?>"  data-type="combodate" onclick='return false;'><?php echo $debutAvenant->format('d/m/Y'); ?></a-->
                <a href="#" id="avenant_debut" data-name="debut" data-pk="<?php echo $avenant->id; ?>"  data-type="select" onclick='return false;'><?php echo $debutAvenant->format('d/m/Y'); ?></a>
                
            </div>
	    <div class="empl-full empl-av-btns" style="border: none">
		<div class='grp clear-auto'>     
                    <?php if(! $avenant->isAvenantInitiale()  ) : ?>
                        <a href='#' class='btn btn-danger  btn-small' id='avenantRemoveButton' data-pk='<?php echo $avenant->id;?>' data-pk_employe='<?php echo $employe->matricule;?>'  >Supprimer l' avenant &nbsp; <i class="icon-white icon-trash"></i></a>
                    <?php endif; ?>

                    <a href="#" class='btn btn-primary btn-small' id="avenantEditButton" onclick="return editAvenant();">
                        Editer l' avenant &nbsp; <i class="icon-white icon-pencil"></i>
                        <!--img src="<?php echo $this->basePath() . '/img/rh/edit-32x32.png' ?>" alt="Editer l'avenant" title="Editer l'Avenant en cours"-->
                    </a>
                </div>
                <div class='grp  clear-auto'>                
                    <?php if ($isCdiAndHasDateDepart): ?>
                        <a href="#" id="avenantNewButton" class="btn btn-info btn-small" style="float: right; opacity: 0.4;" onclick="showError('Il n\'est plus possible d\'ajouter un avenant!');" disabled >Ajouter un nouvel avenant &nbsp;&nbsp;<i class="icon-white icon-plus-sign"></i></a>                       
                    <?php else : ?>
                        <a href="#" id="avenantNewButton" class="btn btn-info btn-small" style="float: right;" onclick="return addAvenant();">Ajouter un nouvel avenant &nbsp;&nbsp;<i class="icon-white icon-plus-sign"></i></a>
                    <?php endif ;?>
                </div>    
	    </div> 
            <!--div class="empl-full empl-gris">
	    <?php
	    $withFin	 = true;
	    if ($avenant->fin == '0000-00-00') {
		$withFin = false;
		//$avenant->fin = '2025-12-31';
	    }
	    $finAvenant	 = new \DateTime($avenant->fin);
	    ?>
                Fin de l'Avenant : <a class="rhdatetime" href="#" id="avenant_fin" data-name="fin" data-pk="<?php echo $avenant->id; ?>"  data-type="combodate" onclick='return false;'><?php echo ($withFin) ? $finAvenant->format('d/m/Y') : 'Aucun'; ?></a>
		<div class="cancel-icon">
		    <a href="#" class="cancel-date" data-id="avenant_fin" data-table="rh_avenant" data-name="fin" data-pk="<?php echo $avenant->id; ?>" title="Effacer la Date">
			<img src="<?php echo $this->basePath() . '/img/rhx/close-12x12.png' ?>" title="Effacer la date">
		    </a>
		</div>
            </div-->
        </div>
	<!-- NOUVELLE AVENANT -->
	<?php
	$debut		 = new RHDateTime($avenant->debut);
	$debut->modify('next day');
	?>
	<div class="empl-group" id="avenantNew" style="display: none;">
            <div class="empl-full empl-jaune">
                Contrat horaire hebdomadaire : <a href='#' id='hebdo' data-type='text' onclick='return false;'>00.0</a> heures
            </div>
            <div class="empl-full empl-jaune">
                Taux horaire : <a href='#' id='taux' data-name="taux" data-type='text' onclick='return false;'>00.0</a> €
            </div>
            <div class="empl-full empl-gris">
                Début : <a href="#" id="debut" data-name="debut" data-type="combodate" onclick='return false;'><?php echo $debut->date('d/m/Y'); ?></a>
            </div>
            <!--div class="empl-full empl-gris">
                Fin de l'Avenant : <a class="rhdatetime" href="#" id="fin" data-type="combodate" onclick='return false;'>00/00/0000</a>
		<div class="cancel-icon">
		    <a href="#" class="cancel-date" data-id="fin" data-name="fin" data-pk="<?php echo $avenant->id; ?>" title="Effacer la Date">
			<img src="<?php echo $this->basePath() . '/img/rhx/close-12x12.png' ?>" title="Effacer la date">
		    </a>
		</div>
            </div-->
	    <form id="avenantNewForm" action="#" method="post">
		<input type="hidden" name="matricule" value="<?php echo $employe->matricule; ?>">
		<input type="hidden" name="poste_id" id="data-poste" value="<?php echo $poste->id; ?>">
		<input type="hidden" name="hebdo" id="data-hebdo" value="0.0">
		<input type="hidden" name="taux" id="data-taux" value="0.0">
		<input type="hidden" name="debut" id="data-debut" value="<?php echo $debut->date(); ?>">
		<input type="hidden" name="fin" id="data-fin" value="0000-00-00">
		<input type="hidden" name="niveau" id="data-niveau" value="1">
		<input type="hidden" name="echelon" id="data-echelon" value="1">
		<input type="hidden" name="college" id="data-college" value="1">
                
                <input type="hidden" name="college" id="data-" value="1">
                <input type='hidden' id='data-<?php echo FileManager ::EMPLOYE_AVENANT_FILE ;?>' name='<?php echo  FileManager ::EMPLOYE_AVENANT_FILE ;?>' value=''>
                <input type='hidden' id='data-<?php echo  FileManager ::EMPLOYE_AVENANT_FILE ;?>-ext' name='<?php echo  FileManager ::EMPLOYE_AVENANT_FILE ;?>_extension' value=''>
	    </form>
        </div>
    </div>

    <!--div class="empl-full"><button class="btn btn-primary" id="avenantAddButton" style="display: none;" onclick="return AddNewAvenant();">Enregistrer</button></div-->

    <!--div class='empl-full bleu-navy' style="clear: both" id='avenant-message'>
	<span>&nbsp;</span>
    </div-->

    <div class="empl-center" style="margin-top: -15px; width: 99%;">
        <div class="empl-group">
            <div class="empl-full vert-olive">
                <a href='#' onclick='return avenantHistory(<?php echo $employe->matricule ?>);' style='font-weight: bolder'>
		    AVENANTS (historique)
		</a>
            </div>
	    <table class='table table-striped table-condensed list-table' style='width: 99%;'>
		<thead>
		    <tr>
			<td>&nbsp;</td>
			<td>Poste</td>
			<td>Collège</td>
			<td>Niveau</td>
			<td>Echelon</td>
			<td>Contrat horaire</td>
			<td>Taux horaire</td>
			<td>Date de Fin</td>
                        <td> </td>
		    </tr>
		</thead>
		<tbody>
		    <?php
		    $history	 = $employe->getAvenantHistory();
		    //var_dump($history);
		    $count		 = is_array($history) ? count($history) : $history->count();
		    $count--;
		    ?>
		    <?php $k		 = 0 ?>
		    <?php foreach ($history as $story): ?>
			<?php
			$av	 = $story->getAvenant();
			$pos	 = $av->getPoste();
			$college = $av->getCollege();
                        $hasLibelle = $av->libelle && $av->libelle != '' ;
                        if($hasLibelle){
                            $nommage = $av->libelle ;
                        }
                        else{
                            $nommage = ($count == 0) ? 'Contrat Initiale' : "Avenant n° $count";
			    // Sauvegarde du libellé
			    /*$av->libelle= $nommage;
			    $avenantTable->save($av);*/
                        }
                        //echo "<pre>$count</pre>";
                        if ($k == 0) {
                            $k++;
                            $count--;
                            continue;
                        }
			$showInfo = strpos($nommage, 'TR');
                        ?>
    		    <tr>
    			<td>
    			    <a href="#" class="full-link" id="av-<?php echo $av->id; ?>" title="<?php echo $av->id; ?>" onclick="return avenantDetails(<?php echo $av->id ?>, '<?php echo $nommage; ?>');">
				    <?php echo $nommage; ?>                               
    			    </a>
    			</td>
    			<td>
    			    <a href="#" class="full-link" id="av-<?php echo $av->id; ?>" onclick="return avenantDetails(<?php echo $av->id ?>, '<?php echo $nommage; ?>');">
				    <?php echo ($showInfo === false) ? $pos->libelle : ''; ?>
    			    </a>
    			</td>
    			<td>
    			    <a href="#" class="full-link" id="av-<?php echo $av->id; ?>" onclick="return avenantDetails(<?php echo $av->id ?>, '<?php echo $nommage; ?>');">
				    <?php echo ($showInfo === false) ? $college->libelle : ''; ?>
    			    </a>
    			</td>
    			<td>
    			    <a href="#" class="full-link" id="av-<?php echo $av->id; ?>" onclick="return avenantDetails(<?php echo $av->id ?>, '<?php echo $nommage; ?>');">
				    <?php echo ($showInfo === false) ? 'Niveau ' . Number::getRomanNumber($av->niveau) : ''; ?>
    			    </a>
    			</td>
    			<td>
    			    <a href="#" class="full-link" id="av-<?php echo $av->id; ?>" onclick="return avenantDetails(<?php echo $av->id ?>, '<?php echo $nommage; ?>');">
				    <?php echo ($showInfo === false) ? 'Echelon ' . $av->echelon : ''; ?>
    			    </a>
    			</td>
    			<td>
    			    <a href="#" class="full-link" id="av-<?php echo $av->id; ?>" onclick="return avenantDetails(<?php echo $av->id ?>, '<?php echo $nommage; ?>');">
				    <?php echo ($showInfo === false) ? number_format($av->hebdo, 2, ',', ' ') : ''; ?>
    			    </a>
    			</td>
    			<td>
    			    <a href="#" class="full-link" id="av-<?php echo $av->id; ?>" onclick="return avenantDetails(<?php echo $av->id ?>, '<?php echo $nommage; ?>');">
				    <?php echo($showInfo === false) ? number_format($av->taux, 2, ',', ' ') : ''; ?>
    			    </a>
    			</td>
    			<td>
    			    <a href="#" class="full-link" id="av-<?php echo $av->id; ?>" onclick="return avenantDetails(<?php echo $av->id ?>, '<?php echo $nommage; ?>');">
				    <?php
				    $fin	 = new RHDateTime($av->fin);
				    echo ($showInfo === false) ? $fin->date('d/m/Y') : '';
				    ?>
    			    </a>
    			</td>
                        <td>
                            <?php $flagFile = $count != 0 ? FileManager::EMPLOYE_AVENANT_FILE :  FileManager::EMPLOYE_CONTRAT_FILE; ?>
                            <?php      $obj = $count != 0 ? 'av' : 'employe'; ?>
                                
                            <?php if($$obj->$flagFile != '') :?>
                                <?php 
                                    $fileManager->setFlag($flagFile);
                                    $repertory = str_replace('public/', '', $fileManager->getUploadDirectory());
                                    $href = $this->basePath() . '/'.  $repertory . $$obj->$flagFile ;
                                ?>
                                <a class='' href='<?php echo $href ;?>' target='_blank'> 
                                    <img src="<?php echo $this->basePath() . '/img/rhx/file-attach.png' ?>" title='Pièces jointes' width='20px' height='20px'/> 
                                </a>
                            <?php endif;?>
                            
                        </td>
    		    </tr>
			<?php
			$k++;
                        $count--;
                        if(!$hasLibelle){
                            //$count--;
                        }
			?>
		    <?php endforeach; ?>
		</tbody>
	    </table>

            <div class="empl-full vert-olive">
                &nbsp;
            </div>
        </div>
    </div>

    <div class='empl-full vert-olive empl-title'>Historique des contrats</div>
    <table class='table table-condensed table-striped list-table'>
	<thead>
	    <tr>
		<td>Dernier Poste</td>
		<td>Date d'entrée</td>
		<td>Date de départ</td>
		<td>Motif de départ</td>
	    </tr>
	</thead>
	<tbody>
	    <?php foreach ($employeHistory as $eh): ?>
		<?php
		$m	 = $eh->getMotif();
		$debut	 = new RHDateTime($eh->contrat_debut);
		$fin		 = new RHDateTime($eh->contrat_fin);
    $posteOld	 = $eh->getPoste();
    ?>
	    <tr>
    		<td><?php echo $posteOld->libelle; ?></td>
    		<td><?php echo $debut->date('d/m/Y'); ?></td>
    		<td><?php echo $fin->date('d/m/Y'); ?></td>
    		<td><?php echo $m->libelle; ?></td>
    	    </tr>
	    <?php endforeach; ?>
	</tbody>
    </table>
    <div class='empl-full vert-olive'>&nbsp;</div>

    <div style="clear: both"></div>

    <div class="content-head">
        <h3>&nbsp;</h3>
        <div class="toolbar">
            <!--<button class='btn btn-primary' style='margin-right: 10px;' onclick="save();">Enregistrer</button>-->
            <button class='btn btn-inverse' onclick="location.href = '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'index', 'id'		 => $employe->site_id, 'other1'	 => 1)) ?>';">Revenir à la liste des employés</button>
        </div>
    </div>

</div>

<div class="empl-center" style="width: 30%">
    <div class="empl-full bleu"><a href='#' onclick='return false;' class='full-link'>Transmission de la fiche à ADEC</a></div>
    <div class="empl-full bleu"><a href='#' onclick='return false;' class='full-link'>Impression Attestation Employeur</a></div>
</div>

<!-- Disponibilité -->
<?php
$disponibilite	 = $employe->getDisponibilite();
//var_dump($employe);
//var_dump($disponibilite);
?>
<div class="empl-border" style='margin-top: 15px'>
    <div class="empl-full bleu empl-title" style='margin-bottom: 10px'>Disponibilité</div>

    <div class="list-container">
        <table class="table table-striped list-table">
            <thead>
                <tr>
                    <td></td>
                    <td class='empl-title' style='text-align: center'>Disponibilité</td>
                    <td class='empl-title' style='text-align: center'>Heure d'arrivée</td>
                    <td class='empl-title' style='text-align: center'>Heure de départ</td>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td class='empl-title' style='text-indent: 15px'>Lundi</td>
                    <td style='text-align: center'>
                        <a class="full-link" href="#" id="lundi" data-type="select" data-name="lundi" data-pk="<?php echo $disponibilite->id ?>">
			    <?php echo ((int) $disponibilite->lundi == 1) ? 'Oui' : 'Non' ?>
                        </a>
                    </td>
                    <td style='text-align: center'>
                        <a class="full-link" href="#" id="lundi_entree" data-type="combodate" data-template='HH:mm' data-format="HH:mm" data-viewformat="HH:mm" data-name="lundi_entree" data-pk="<?php echo $disponibilite->id; ?>">
			    <?php
			    $time		 = new RHDateTime($disponibilite->lundi_entree);
			    echo $time->hours();
			    ?>
                        </a>
                    </td>
                    <td style='text-align: center'>
			<a class="full-link" href="#" id="lundi_sortie" data-type="combodate" data-template='HH:mm' data-format="HH:mm" data-viewformat="HH:mm" data-name="lundi_sortie" data-pk="<?php echo $disponibilite->id; ?>">
			    <?php
			    $time		 = new RHDateTime($disponibilite->lundi_sortie);
			    echo $time->hours();
			    ?>
                        </a>
                    </td>
                </tr>
                <tr>
                    <td class='empl-title' style='text-indent: 15px'>Mardi</td>
                    <td style='text-align: center'>
                        <a class="full-link" href="#" id="mardi" data-type="select" data-name="mardi" data-pk="<?php echo $disponibilite->id ?>">
			    <?php echo ((int) $disponibilite->mardi == 1) ? 'Oui' : 'Non' ?>
                        </a>
                    </td>
                    <td style='text-align: center'>
                        <a class="full-link" href="#" id="mardi_entree" data-type="combodate" data-template='HH:mm' data-format="HH:mm" data-viewformat="HH:mm" data-name="mardi_entree" data-pk="<?php echo $disponibilite->id; ?>">
			    <?php
			    $time		 = new RHDateTime($disponibilite->mardi_entree);
			    echo $time->hours();
			    ?>
                        </a>
                    </td>
                    <td style='text-align: center'>
                        <a class="full-link" href="#" id="mardi_sortie" data-type="combodate" data-template='HH:mm' data-format="HH:mm" data-viewformat="HH:mm" data-name="mardi_sortie" data-pk="<?php echo $disponibilite->id; ?>">
			    <?php
			    $time		 = new RHDateTime($disponibilite->mardi_sortie);
			    echo $time->hours();
			    ?>
                        </a>
                    </td>
                </tr>
                <tr>
                    <td class='empl-title' style='text-indent: 15px'>Mercredi</td>
                    <td style='text-align: center'>
                        <a class="full-link" href="#" id="mercredi" data-type="select" data-name="mercredi" data-pk="<?php echo $disponibilite->id ?>">
			    <?php echo ((int) $disponibilite->mercredi == 1) ? 'Oui' : 'Non' ?>
                        </a>
                    </td>
                    <td style='text-align: center'>
                        <a class="full-link" href="#" id="mercredi_entree" data-type="combodate" data-template='HH:mm' data-format="HH:mm" data-viewformat="HH:mm" data-name="mercredi_entree" data-pk="<?php echo $disponibilite->id; ?>">
			    <?php
			    $time		 = new RHDateTime($disponibilite->mercredi_entree);
			    echo $time->hours();
			    ?>
                        </a>
                    </td>
                    <td style='text-align: center'>
                        <a class="full-link" href="#" id="mercredi_sortie" data-type="combodate" data-template='HH:mm' data-format="HH:mm" data-viewformat="HH:mm" data-name="mercredi_sortie" data-pk="<?php echo $disponibilite->id; ?>">
			    <?php
			    $time		 = new RHDateTime($disponibilite->mercredi_sortie);
			    echo $time->hours();
			    ?>
                        </a>
                    </td>
                </tr>
                <tr>
                    <td class='empl-title' style='text-indent: 15px'>Jeudi</td>
                    <td style='text-align: center'>
                        <a class="full-link" href="#" id="jeudi" data-type="select" data-name="jeudi" data-pk="<?php echo $disponibilite->id ?>">
			    <?php echo ((int) $disponibilite->jeudi == 1) ? 'Oui' : 'Non' ?>
                        </a>
                    </td>
                    <td style='text-align: center'>
                        <a class="full-link" href="#" id="jeudi_entree" data-type="combodate" data-template='HH:mm' data-format="HH:mm" data-viewformat="HH:mm" data-name="jeudi_entree" data-pk="<?php echo $disponibilite->id; ?>">
			    <?php
			    $time		 = new RHDateTime($disponibilite->jeudi_entree);
			    echo $time->hours();
			    ?>
                        </a>
                    </td>
                    <td style='text-align: center'>
                        <a class="full-link" href="#" id="jeudi_sortie" data-type="combodate" data-template='HH:mm' data-format="HH:mm" data-viewformat="HH:mm" data-name="jeudi_sortie" data-pk="<?php echo $disponibilite->id; ?>">
			    <?php
			    $time		 = new RHDateTime($disponibilite->jeudi_sortie);
			    echo $time->hours();
			    ?>
                        </a>
                    </td>
                </tr>
                <tr>
                    <td class='empl-title' style='text-indent: 15px'>Vendredi</td>
                    <td style='text-align: center'>
                        <a class="full-link" href="#" id="vendredi" data-type="select" data-name="vendredi" data-pk="<?php echo $disponibilite->id ?>">
			    <?php echo ((int) $disponibilite->vendredi == 1) ? 'Oui' : 'Non' ?>
                        </a>
                    </td>
                    <td style='text-align: center'>
                        <a class="full-link" href="#" id="vendredi_entree" data-type="combodate" data-template='HH:mm' data-format="HH:mm" data-viewformat="HH:mm" data-name="vendredi_entree" data-pk="<?php echo $disponibilite->id; ?>">
			    <?php
			    $time		 = new RHDateTime($disponibilite->vendredi_entree);
			    echo $time->hours();
			    ?>
                        </a>
                    </td>
                    <td style='text-align: center'>
                        <a class="full-link" href="#" id="vendredi_sortie" data-type="combodate" data-template='HH:mm' data-format="HH:mm" data-viewformat="HH:mm" data-name="vendredi_sortie" data-pk="<?php echo $disponibilite->id; ?>">
			    <?php
			    $time		 = new RHDateTime($disponibilite->vendredi_sortie);
			    echo $time->hours();
			    ?>
                        </a>
                    </td>
                </tr>
                <tr>
                    <td class='empl-title' style='text-indent: 15px'>Samedi</td>
                    <td style='text-align: center'>
                        <a class="full-link" href="#" id="samedi" data-type="select" data-name="samedi" data-pk="<?php echo $disponibilite->id ?>">
			    <?php echo ((int) $disponibilite->samedi == 1) ? 'Oui' : 'Non' ?>
                        </a>
                    </td>
                    <td style='text-align: center'>
                        <a class="full-link" href="#" id="samedi_entree" data-type="combodate" data-template='HH:mm' data-format="HH:mm" data-viewformat="HH:mm" data-name="samedi_entree" data-pk="<?php echo $disponibilite->id; ?>">
			    <?php
			    $time		 = new RHDateTime($disponibilite->samedi_entree);
			    echo $time->hours();
			    ?>
                        </a>
                    </td>
                    <td style='text-align: center'>
                        <a class="full-link" href="#" id="samedi_sortie" data-type="combodate" data-template='HH:mm' data-format="HH:mm" data-viewformat="HH:mm" data-name="samedi_sortie" data-pk="<?php echo $disponibilite->id; ?>">
			    <?php
			    $time		 = new RHDateTime($disponibilite->samedi_sortie);
			    echo $time->hours();
			    ?>
                        </a>
                    </td>
                </tr>
                <tr>
                    <td class='empl-title' style='text-indent: 15px'>Dimanche</td>
                    <td style='text-align: center'>
                        <a class="full-link" href="#" id="dimanche" data-type="select" data-name="dimanche" data-pk="<?php echo $disponibilite->id ?>">
			    <?php echo ((int) $disponibilite->dimanche == 1) ? 'Oui' : 'Non' ?>
                        </a>
                    </td>
                    <td style='text-align: center'>
                        <a class="full-link" href="#" id="dimanche_entree" data-type="combodate" data-template='HH:mm' data-format="HH:mm" data-viewformat="HH:mm" data-name="dimanche_entree" data-pk="<?php echo $disponibilite->id; ?>">
			    <?php
			    $time		 = new RHDateTime($disponibilite->dimanche_entree);
			    echo $time->hours();
			    ?>
                        </a>
                    </td>
                    <td style='text-align: center'>
                        <a class="full-link" href="#" id="dimanche_sortie" data-type="combodate" data-template='HH:mm' data-format="HH:mm" data-viewformat="HH:mm" data-name="dimanche_sortie" data-pk="<?php echo $disponibilite->id; ?>">
			    <?php
			    $time		 = new RHDateTime($disponibilite->dimanche_sortie);
			    echo $time->hours();
			    ?>
                        </a>
                    </td>
                </tr>
            </tbody>

        </table>
    </div>

    <div style="clear: both; height: 2em;"></div>

    <div class="content-head">
        <h3>&nbsp;</h3>
        <div class="toolbar">
            <!--<button class='btn btn-primary' style='margin-right: 10px;' onclick="save();">Enregistrer</button>-->
            <button class='btn btn-inverse' onclick="location.href = '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'index', 'id'		 => $employe->site_id, 'other1'	 => 1)) ?>';">Revenir à la liste des employés</button>
        </div>
    </div>
</div>


<div id='avenant-dialog'></div>

<script type="text/javascript">
	    // Démarrage
	    $(document).ready(function() {
                
        <?php if(!$isTranfered) : // BEGIN JS POUR EMP TRANSFERE ?>
		$('#nom').editable({
		    title: "Nom",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>/1",
		    validate: function(value) {
			nom = value;
                        nom_upper = value.toUpperCase();
			$('#data-nom').val(nom_upper);
                        $('#title-employe-nom').text( nom_upper  );
		    },
		    inputclass: 'uppercase',
		    params: function(params) {
			value = params.value;
			uppercase = value.toUpperCase();
			params.value = uppercase;
			return params;
		    }
		});
    
		$('#nom2').editable({
		    title: "Nom",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>/1",
		    validate: function(value) {
			nom2 = value;
			$('#data-nom2').val(value.toUpperCase());
		    },
		    inputclass: 'uppercase',
		    params: function(params) {
			value = params.value;
			uppercase = value.toUpperCase();
			params.value = uppercase;
			return params;
		    }
		});
                
                $('#prenom').editable({
		    title: "Prénom",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>",
		    validate: function(value) {
			prenom = value;
			$('#data-prenom').val(value);
                        $('#title-employe-prenom').text( toTitleCase(value)  );
		    },
		    inputclass: 'capitalize',
		    params: function(params) {
			value = params.value;
			capitalize = toTitleCase(value);
			params.value = capitalize;
			return params;
		    }
		});
                
                $('#date_naissance').editable({
		    title: 'Date de naissance',
		    format: 'DD/MM/YYYY',
		    template: 'D / MMMM / YYYY',
		    placement: 'left',
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>",
		    params: function(params) {
			value = params.value;
			date = moment(value, ['YYYY-MM-DD', 'DD/MM/YYYY']);
			params.value = date.format('YYYY-MM-DD');
			return params;
		    },
		    combodate: {
			minYear: 1900,
			maxYear: 2000,
			minuteStep: 1
		    },
		    validate: function(value) {
			val = value.year() + '-' + (parseInt(value.month()) + 1) + '-' + value.date();
			age = calcul_age(val);
			if (age < 18) {
			    showError("Attention !!!<br>L'employé a moins de 18 ans");
			    return false;
			}
		    }
		});
                $('#lieu_naissance').editable({
		    title: "Lieu de naissance",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>",
		    validate: function(value) {
			lieu_naissance = value;
			$('#data-lieu_naissance').val(value);
		    }
		});
                
		$('#pays_naissance').editable({
		    title: "Pays de naissance",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>",
		    validate: function(value) {
			pays_naissance = value;
			$('#data-pays_naissance').val(value);
		    }
		});
                
                $('#nationalite').editable({
		    title: "Nationalité",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeIntData')) ?>",
		    source: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'getNationaliteList')) ?>"
		});
                
                $('#adresse1').editable({
		    title: "Adresse",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>",
		    validate: function(value) {
			adresse1 = value;
			$('#data-adresse1').val(value);
		    }
		});
                $('#adresse2').editable({
		    title: "Adresse",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>",
		    validate: function(value) {
			adresse2 = value;
			$('#data-adresse2').val(value);
		    }
		});
                
                $('#cp1').editable({
		    title: "Code Postal",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>",
		    validate: function(value) {
			cp1 = value;
			$('#data-cp1').val(value);
		    }
		});
                
                $('#cp2').editable({
		    title: "Code Postal",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>",
		    validate: function(value) {
			cp2 = value;
			$('#data-cp2').val(value);
		    }
		});
                $('#ville1').editable({
		    title: "Ville",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>",
		    validate: function(value) {
			ville1 = value;
			$('#data-ville1').val(value);
		    }
		});
		$('#ville2').editable({
		    title: "Ville",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>",
		    validate: function(value) {
			ville2 = value;
			$('#data-ville2').val(value);
		    }
		});
                
                $('#num_mobile').editable({
		    title: "Numéro du téléphone Mobile",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>",
		    validate: function(value) {
			num_mobile = value;
			$('#data-num_mobile').val(value);
		    }
		});
		$('#email').editable({
		    title: "Adresse Email",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>",
		    validate: function(value) {
			email = value;
			$('#data-email').val(value);
		    }
		});
                
                $('#titre_sejour').editable({
		    title: "Titre de Séjour",
		    source: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'sejourList')) ?>",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeIntData')) ?>",
		    validate: function(value) {
			titre_sejour = value;
			$('#data-titre_sejour').val(value);
		    }
		});
                
                $('#num_titre_sejour').editable({
		    title: "Numéro du titre de Séjour",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>",
		    validate: function(value) {
			num_titre_sejour = value;
			$('#data-num_titre_sejour').val(value);
		    }
		});
                $('#date_fin_validite_sejour').editable({
		    title: 'Date de Fin de Séjour',
		    format: 'DD/MM/YYYY',
		    template: 'D / MMMM / YYYY',
		    placement: 'left',
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>",
		    params: function(params) {
			value = params.value;
			date = moment(value, ['YYYY-MM-DD', 'DD/MM/YYYY']);
			params.value = date.format('YYYY-MM-DD');
			return params;
		    },
		    combodate: {
			minYear: 1950,
			maxYear: 2025,
			minuteStep: 1
		    },
		    validate: function(value) {
			val = value.year() + '-' + (parseInt(value.month()) + 1) + '-' + value.date();
			if (moment('<?php echo date('Y-m-d'); ?>').isSame(val)) {
			    //$('#data-sejour_fin').val(val);
			} else {
			    if (moment().isAfter(val)) {
				showError("ATTENTION!!!<br>La date de Fin de validité est antérieur ou égale à la date du Jour");
			    } else {
				//$('#data-sejour_fin').val(val);
			    }
			}
		    }
		});
                // CODE Caise TC POS
		$('#code_caisse').editable({
		    title: 'Saisie du Code Caisse',
		    url: '<?php echo $this->url("RHX/default", array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>'
		});
                $('#num_cpam').editable({
		    title: "Numéro CPAM",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>",
		    validate: function(value) {
			num_cpam = value;
			$('#data-num_cpam').val(value);
		    }
		});
      
		
		$('#situation_familiale').editable({
		    title: "Situation familiale",
		    source: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'jsonsituationlist')) ?>",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>",
		    validate: function(value) {
			situation_familiale = value;
			$('#data-situation_familiale').val(value);
		    }
		});
		$('#nombre_enfant').editable({
		    title: "Nombre d'enfant",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeIntData')) ?>",
		    params: function(params) {
			value = parseInt(params.value);
			if (!isNaN(value)) {
			    //showError(value + " est un nombre");
			    params.value = value;
			} else {
			    //showError(value + " n'est pas un nombre");
			    params.value = 0;
			}
			return params;
		    },
		    validate: function(value) {
			nb_enfant = value;
			$('#data-nb_enfant').val(value);
		    },
		    success: function(response, newValue) {
			ajax = $.ajax({
			    type: 'post',
			    url: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'getEmployeInfo')) ?>',
			    data: '&matricule=<?php echo $employe->matricule; ?>'
			});
			ajax.done(function(result) {
			    info = result.info;
			    $('#nombre_enfant').text(info.enfant);
			});
		    }
		});
		$('#num_pole_emploi').editable({
		    title: "Numéro Pole Emploi",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>",
		    validate: function(value) {
			num_pole_emploi = value;
			$('#data-num_pole_emploi').val(value);
		    }
		});
		$('#mutuelle').editable({
		    title: "Mutuelle",
		    source: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'mutuelleList')) ?>',
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeIntData')) ?>",
		    validate: function(value) {
			mutuelle = value;
			$('#data-mutuelle').val(value);
		    }
		});
		$('#titre_transport').editable({
		    title: "Titre de transport",
		    source: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'jsontransportlist')) ?>",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeIntData')) ?>",
		    validate: function(value) {
			titre_transport = value;
			$('#data-transport_id').val(value);
		    }
		});
		$('#date_effet').editable({
		    title: "Date d'effet",
		    format: 'DD/MM/YYYY',
		    template: 'D / MMMM / YYYY',
		    placement: 'left',
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>",
		    params: function(params) {
			value = params.value;
			date = moment(value, ['YYYY-MM-DD', 'DD/MM/YYYY']);
			params.value = date.format('YYYY-MM-DD');
			return params;
		    },
		    combodate: {
			minYear: 1950,
			maxYear: 2025,
			minuteStep: 1
		    }
		});
		$('#vehicule_fonction').editable({
		    title: "Véhicule de fonction",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>",
		    validate: function(value) {
			vehicule_fonction = value;
			$('#data-vehicule_fonction').val(value);
		    }
		});
		$('#immatriculation').editable({
		    title: "Immatriculation du véhicule",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>",
		    validate: function(value) {
			immatriculation = value;
			$('#data-immatriculation').val(value);
		    }
		});
		$('#date_visite').editable({
		    title: "Dernière Date de visite Médicale",
		    format: 'DD/MM/YYYY',
		    template: 'D / MMMM / YYYY',
		    placement: 'left',
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeSanteData')) ?>",
		    params: function(params) {
			value = params.value;
			date = moment(value, ['YYYY-MM-DD', 'DD/MM/YYYY']);
			params.value = date.format('YYYY-MM-DD');
			return params;
		    },
		    combodate: {
			minYear: 1950,
			maxYear: 2025,
			minuteStep: 1
		    }
		});
		$('#num_permis').editable({
		    title: "Numéro du Permis de conduire",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>",
		    validate: function(value) {
			num_permis = value;
			$('#data-num_permis').val(value);
		    }
		});
		
		
		$('#rib').editable({
		    title: "RIB",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>",
		    validate: function(value) {
			rib = value;
			$('#data-rib').val(value);
		    }
		});
		// Contrat
		$('#contrat_type').editable({
		    title: 'Type de contrat',
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeIntData')) ?>",
		    source: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'contratTypeList')) ?>",
		    validate: function(value) {
			var $finContrat =  $('#fin_contrat'),
                            $departMotif = $('#depart_motif'),
                            $ruptureContrat = $('#btn-rupture-contrat') 
                            ;
                    
			$('#data-contrat_type').val(value);

                        isCdi = value === '1' || value === '0' ;
                        
                        $finContrat.parent().css('display', isCdi ?  'none' : '');
                        $departMotif.parent().css('display', isCdi ?  'none' : '');
                        $ruptureContrat.css('display', !isCdi ?  'none' : '');
                        
                        if(isCdi){ 
                            $.ajax({ // update contrat_fin
                               type: 'post',
                               url: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>',
                               data: '&pk=' + $(this).attr('data-pk') + '&name=contrat_fin' + '&value=0000-00-00'
                            });
                           $finContrat.html('Aucun');
                           
                           
                           $.ajax({ // update motif depart 
                               type: 'post',
                               url: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>',
                               data: '&pk=' + $(this).attr('data-pk') + '&name=contrat_motif_depart' + '&value=0'
                            });
                           $departMotif.html('Aucun');  
                           
                           $.ajax({ 
                               type: 'post',
                               url: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>',
                               data: '&pk=' + $(this).attr('data-pk') + '&name=actif' + '&value=1'
                            });
                           $('#data-employe_active').val(1); 
                           
                        }
                        else{
                        }
		    },
		    inputclass: 'input-large'
		});
                
                 
		$('#etatcivil').editable({
		    title: 'Etat Civil',
		    showbuttons: false,
		    value: <?php echo $employe->civil_id ?>,
		    source: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'jsonetatcivillist')) ?>",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeIntData')) ?>",
		    validate: function(value) {
			etatCivil = value;
			
		    }
		});
		$('#site').editable({
		    title: "Site Employeur",
		    showbuttons: false,
		    source: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'jsonSiteList')) ?>",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeIntData')) ?>",
		    validate: function(value) {
			site = value;
			$('#data-site_id').val(value);
		    }
		});
         <?php endif ;// END JS POUR EMP TRANSFERE ?>             
                // Rupture contrat
                $("#btn-rupture-contrat").on('click', function(){
                    var $this        = $(this);
                        $finContrat  = $('#fin_contrat'),
                        $departMotif = $('#depart_motif'),
                        $avenantNewBouton = $('#avenantNewButton');
                        
                    $this.hide(); 
                    $finContrat.parent().show();    
                    $departMotif.parent().show();    
                    hide_or_show({
                                hide: [$this] , 
                                show: [ $finContrat.parent(), $departMotif.parent(), $("#btn-rupture-contrat-cancel")]
                              });
                    
                    $('#data-employe_active').val(0);
                    // update motif depart
                    idMotifdep = 0;
                    $.ajax({ 
                               type: 'post',
                               url: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>',
                               data: '&pk=' + $(this).attr('data-pk') + '&name=contrat_motif_depart' + '&value='+ idMotifdep
                            });
                    $departMotif.html('Aucun');
                    
                    // date de depart
                    $.ajax({
                               type: 'post',
                               url: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>',
                               data: '&pk=' + $(this).attr('data-pk') + '&name=contrat_fin' + '&value=0000-00-00'
                            });
                    $finContrat.html('Aucun');                                      
                });
                
                $('#btn-rupture-contrat-cancel').on('click', function(){
                     var $this        = $(this);
                        $finContrat  = $('#fin_contrat'),
                        $departMotif = $('#depart_motif'),
                        $avenantNewBouton = $('#avenantNewButton');
                    
                    hide_or_show({
                                hide: [$this, $finContrat.parent(), $departMotif.parent()] , 
                                show: [$("#btn-rupture-contrat")]
                              });
                    
                    idMotifdep = 0;
                    $.ajax({ 
                               type: 'post',
                               url: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>',
                               data: '&pk=' + $(this).attr('data-pk') + '&name=contrat_motif_depart' + '&value='+ idMotifdep
                            });
                    $departMotif.html('Aucun');
                    
                    $.ajax({
                               type: 'post',
                               url: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>',
                               data: '&pk=' + $(this).attr('data-pk') + '&name=contrat_fin' + '&value=0000-00-00'
                            });
                    $finContrat.html('Aucun');
                });
                
                /* effacer et afficher des objet jQuery
                 * @param obj.show : array des objets à afficher
                 * @param obj.hide : array des objets à effacer
                 */
                function hide_or_show(obj){
                    IdsToShow = obj.show;
                    IdsToHide = obj.hide;
                    $(IdsToShow).each(function(k, $jObj){
                        $jObj.show();
                    });
                    $(IdsToHide).each(function(k, $jObj){
                        $jObj.hide();
                    });
                }
		$('#debut_contrat').editable({
		    title: 'Début de Contrat',
		    format: 'DD/MM/YYYY',
		    template: 'D / MMMM / YYYY',
		    placement: 'left',
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringDataContratDate')) ?>",
		    params: function(params) {
			value = params.value;
			date = moment(value, ['YYYY-MM-DD', 'DD/MM/YYYY']);
			params.value = date.format('YYYY-MM-DD');
			return params;
		    },
		    validate: function(value) {
			val = value.year() + '-' + (parseInt(value.month()) + 1) + '-' + value.date();
                        /*
			if (moment('<?php echo date('Y-m-d'); ?>').isAfter(val)) {
			    showError("ATTENTION!!!\nLa date du début du contrat est antérieure à la date du jour");
			}*/

		    },
		    success: function(data){                        
                        if(data && data.error){                            
                            return data.error;
                        }
                        else if(data && data.success){
                            //return data.success;
                        }
                        
                        updateAllPlanningType({
                                    onSuccess : function (){  updateAllPlanningSemaine();}
                            });
		    }
		});
		$('#fin_contrat').editable({
		    title: 'Fin de Contrat',
		    format: 'DD/MM/YYYY',
		    template: 'D / MMMM / YYYY',
		    placement: 'left',
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringDataContratDate')) ?>",
		    params: function(params) {
			value = params.value;
			date = moment(value, ['YYYY-MM-DD', 'DD/MM/YYYY']);
			params.value = date.format('YYYY-MM-DD');
			return params;
		    },
                    validate: function(value) {						 
                         
		    },
		    success: function(data){
                        var $avenantNewBouton = $('#avenantNewButton'),
                            isCdi   = $('#data-contrat_type').val() == '1' || $('#data-contrat_type').val() == '0' ,
                            isActif = $('#data-employe_active').val() == '1';
                        
			if(data && data.error){                            
                            return data.error;
                        }
                        else if(data && data.success){
                            //return data.success;
                        }
                        // if saving ok
                        updateAllPlanningType({
                                    onSuccess : function (){ updateAllPlanningSemaine();}
                            });
                            
                         // fermer contrat, avenant en cours            
                         if(isCdi && !isActif){ 
                            //val = value.year() + '-' + (parseInt(value.month()) + 1) + '-' + value.date();
                            val = data.nouvelle_date;
                            idAvenantEncours = $('#data-avenant_encours').val();
                            
                            $.ajax({ // fermer avenant
                               type: 'post',
                               url: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveAvenantIntData')) ?>',
                               data: '&pk=' + idAvenantEncours + '&name=fin' + '&value='+val,
                               success : function(data){
                               }
                            });
                         }
                         
                        // desactiver ajout avenant
                        if(isCdi && !isActif){                            
                            $avenantNewBouton.attr('disabled', true).attr('onclick', '').css('opacity', '0.4');
                            $avenantNewBouton.on('click', function(){
                                       showError("Il n'est plus possible d'ajouter un avenant!");
                                    });
                            // desactiver ajout contrat
                            $('.contrat-add').css('opacity', '0.5');
                            $('.contrat-add').attr('onclick', '').on('click', function(){
                                       showError("Il n'est plus possible d'ajouter un contrat ! ");
                                    });
                            //desactiver effacer date de depart 
                        }
		    }
		});
		$('#depart_motif').editable({
		    title: 'Motif de départ',
		    url: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeIntData')) ?>',
		    source: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'jsonMotifList')) ?>',
		    validate: function(value) {
			depart_motif = value;
			$('#data-depart_motif').val(value);
		    }
		});

		// Disponibilite
		$('#lundi_entree').editable({
		    placement: 'right',
		    format: 'HH:mm',
		    combodate: {
			firstItem: 'name'
		    },
		    title: "Heure & Minute",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteStringData')) ?>",
		    validate: function(value) {
			var val = value.hour() + ':' + value.minute();
			$('#data-lundi_entree').val(val);
		    }
		});
		$('#mardi_entree').editable({
		    placement: 'right',
		    combodate: {
			firstItem: 'name'
		    },
		    title: "Heure & Minute",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteStringData')) ?>",
		    validate: function(value) {
			var val = value.hour() + ':' + value.minute();
			$('#data-mardi_entree').val(val);
		    }
		});
		$('#mercredi_entree').editable({
		    placement: 'right',
		    combodate: {
			firstItem: 'name'
		    },
		    title: "Heure & Minute",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteStringData')) ?>",
		    validate: function(value) {
			var val = value.hour() + ':' + value.minute();
			$('#data-mercredi_entree').val(val);
		    }
		});
		$('#jeudi_entree').editable({
		    placement: 'right',
		    combodate: {
			firstItem: 'name'
		    },
		    title: "Heure & Minute",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteStringData')) ?>",
		    validate: function(value) {
			var val = value.hour() + ':' + value.minute();
			$('#data-jeudi_entree').val(val);
		    }
		});
		$('#vendredi_entree').editable({
		    placement: 'right',
		    combodate: {
			firstItem: 'name'
		    },
		    title: "Heure & Minute",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteStringData')) ?>",
		    validate: function(value) {
			var val = value.hour() + ':' + value.minute();
			$('#data-vendredi_entree').val(val);
		    }
		});
		$('#samedi_entree').editable({
		    placement: 'right',
		    combodate: {
			firstItem: 'name'
		    },
		    title: "Heure & Minute",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteStringData')) ?>",
		    validate: function(value) {
			var val = value.hour() + ':' + value.minute();
			$('#data-samedi_entree').val(val);
		    }
		});
		$('#dimanche_entree').editable({
		    placement: 'right',
		    combodate: {
			firstItem: 'name'
		    },
		    title: "Heure & Minute",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteStringData')) ?>",
		    validate: function(value) {
			var val = value.hour() + ':' + value.minute();
			$('#data-dimanche_entree').val(val);
		    }
		});
		//
		$('#lundi_sortie').editable({
		    placement: 'right',
		    combodate: {
			firstItem: 'name'
		    },
		    title: "Heure & Minute",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteStringData')) ?>",
		    validate: function(value) {
			var val = value.hour() + ':' + value.minute();
			$('#data-lundi_sortie').val(val);
		    }
		});
		$('#mardi_sortie').editable({
		    placement: 'right',
		    combodate: {
			firstItem: 'name'
		    },
		    title: "Heure & Minute",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteStringData')) ?>",
		    validate: function(value) {
			var val = value.hour() + ':' + value.minute();
			$('#data-mardi_sortie').val(val);
		    }
		});
		$('#mercredi_sortie').editable({
		    placement: 'right',
		    combodate: {
			firstItem: 'name'
		    },
		    title: "Heure & Minute",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteStringData')) ?>",
		    validate: function(value) {
			var val = value.hour() + ':' + value.minute();
			$('#data-mercredi_sortie').val(val);
		    }
		});
		$('#jeudi_sortie').editable({
		    placement: 'right',
		    combodate: {
			firstItem: 'name'
		    },
		    title: "Heure & Minute",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteStringData')) ?>",
		    validate: function(value) {
			var val = value.hour() + ':' + value.minute();
			$('#data-jeudi_sortie').val(val);
		    }
		});
		$('#vendredi_sortie').editable({
		    placement: 'right',
		    combodate: {
			firstItem: 'name'
		    },
		    title: "Heure & Minute",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteStringData')) ?>",
		    validate: function(value) {
			var val = value.hour() + ':' + value.minute();
			$('#data-vendredi_sortie').val(val);
		    }
		});
		$('#samedi_sortie').editable({
		    placement: 'right',
		    combodate: {
			firstItem: 'name'
		    },
		    title: "Heure & Minute",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteStringData')) ?>",
		    validate: function(value) {
			var val = value.hour() + ':' + value.minute();
			$('#data-samedi_sortie').val(val);
		    }
		});
		$('#dimanche_sortie').editable({
		    placement: 'right',
		    combodate: {
			firstItem: 'name'
		    },
		    title: "Heure & Minute",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteStringData')) ?>",
		    validate: function(value) {
			var val = value.hour() + ':' + value.minute();
			$('#data-dimanche_sortie').val(val);
		    }
		});
		//
		$('#dimanche').editable({
		    title: "Disponibilité",
		    source: [{value: 3, text: 'Non'}, {value: 1, text: 'Oui'}],
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteIntData')) ?>",
		    validate: function(value) {
			$('#data-dimanche').val(value);
			//showError(value);
			if (value == 3) {
			    $("#dimanche_entree").text("00:00");
			    $("#data-dimanche_entree").val("00:00");
			    $("#dimanche_sortie").text("00:00");
			    $("#data-dimanche_sortie").val("00:00");
			    ajaxE = $.ajax({
				type: 'post',
				url: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteStringData')) ?>',
				data: '&pk=' + $(this).attr('data-pk') + '&name=dimanche_entree&value=' + '00:00'
			    });
			    ajaxS = $.ajax({
				type: 'post',
				url: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteStringData')) ?>',
				data: '&pk=' + $(this).attr('data-pk') + '&name=dimanche_sortie&value=' + '00:00'
			    });
			}else{
			    $("#dimanche_entree").text("07:00");
			    $("#data-dimanche_entree").val("07:00");
			    $("#dimanche_sortie").text("23:00");
			    $("#data-dimanche_sortie").val("23:00");
			    ajaxE = $.ajax({
				type: 'post',
				url: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteStringData')) ?>',
				data: '&pk=' + $(this).attr('data-pk') + '&name=dimanche_entree&value=' + '07:00'
			    });
			    ajaxS = $.ajax({
				type: 'post',
				url: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteStringData')) ?>',
				data: '&pk=' + $(this).attr('data-pk') + '&name=dimanche_sortie&value=' + '23:00'
			    });
			}
		    }
		});
		$('#lundi').editable({
		    title: "Disponibilité",
		    source: [{value: 3, text: 'Non'}, {value: 1, text: 'Oui'}],
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteIntData')) ?>",
		    validate: function(value) {
			$('#data-lundi').val(value);
			if (value == 3) {
			    $("#lundi_entree").text("00:00");
			    $("#data-lundi_entree").val("00:00");
			    $("#lundi_sortie").text("00:00");
			    $("#data-lundi_sortie").val("00:00");
			    ajaxE = $.ajax({
				type: 'post',
				url: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteStringData')) ?>',
				data: '&pk=' + $(this).attr('data-pk') + '&name=lundi_entree&value=' + '00:00'
			    });
			    ajaxS = $.ajax({
				type: 'post',
				url: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteStringData')) ?>',
				data: '&pk=' + $(this).attr('data-pk') + '&name=lundi_sortie&value=' + '00:00'
			    });
			}else{
			    $("#lundi_entree").text("07:00");
			    $("#data-lundi_entree").val("07:00");
			    $("#lundi_sortie").text("23:00");
			    $("#data-lundi_sortie").val("23:00");
			    ajaxE = $.ajax({
				type: 'post',
				url: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteStringData')) ?>',
				data: '&pk=' + $(this).attr('data-pk') + '&name=lundi_entree&value=' + '07:00'
			    });
			    ajaxS = $.ajax({
				type: 'post',
				url: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteStringData')) ?>',
				data: '&pk=' + $(this).attr('data-pk') + '&name=lundi_sortie&value=' + '23:00'
			    });
			}
		    }
		});
		$('#mardi').editable({
		    title: "Disponibilité",
		    source: [{value: 3, text: 'Non'}, {value: 1, text: 'Oui'}],
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteIntData')) ?>",
		    validate: function(value) {
			$('#data-mardi').val(value);
			if (value == 3) {
			    $("#mardi_entree").text("00:00");
			    $("#data-mardi_entree").val("00:00");
			    $("#mardi_sortie").text("00:00");
			    $("#data-mardi_sortie").val("00:00");
			    ajaxE = $.ajax({
				type: 'post',
				url: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteStringData')) ?>',
				data: '&pk=' + $(this).attr('data-pk') + '&name=mardi_entree&value=' + '00:00'
			    });
			    ajaxS = $.ajax({
				type: 'post',
				url: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteStringData')) ?>',
				data: '&pk=' + $(this).attr('data-pk') + '&name=mardi_sortie&value=' + '00:00'
			    });
			}else{
			    $("#mardi_entree").text("07:00");
			    $("#data-mardi_entree").val("07:00");
			    $("#mardi_sortie").text("23:00");
			    $("#data-mardi_sortie").val("23:00");
			    ajaxE = $.ajax({
				type: 'post',
				url: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteStringData')) ?>',
				data: '&pk=' + $(this).attr('data-pk') + '&name=mardi_entree&value=' + '07:00'
			    });
			    ajaxS = $.ajax({
				type: 'post',
				url: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteStringData')) ?>',
				data: '&pk=' + $(this).attr('data-pk') + '&name=mardi_sortie&value=' + '23:00'
			    });
			}
		    }
		});
		$('#mercredi').editable({
		    title: "Disponibilité",
		    source: [{value: 3, text: 'Non'}, {value: 1, text: 'Oui'}],
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteIntData')) ?>",
		    validate: function(value) {
			$('#data-mercredi').val(value);
			if (value == 3) {
			    $("#mercredi_entree").text("00:00");
			    $("#data-mercredi_entree").val("00:00");
			    $("#mercredi_sortie").text("00:00");
			    $("#data-mercredi_sortie").val("00:00");
			    ajaxE = $.ajax({
				type: 'post',
				url: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteStringData')) ?>',
				data: '&pk=' + $(this).attr('data-pk') + '&name=mercredi_entree&value=' + '00:00'
			    });
			    ajaxS = $.ajax({
				type: 'post',
				url: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteStringData')) ?>',
				data: '&pk=' + $(this).attr('data-pk') + '&name=mercredi_sortie&value=' + '00:00'
			    });
			}else{
			    $("#mercredi_entree").text("07:00");
			    $("#data-mercredi_entree").val("07:00");
			    $("#mercredi_sortie").text("23:00");
			    $("#data-mercredi_sortie").val("23:00");
			    ajaxE = $.ajax({
				type: 'post',
				url: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteStringData')) ?>',
				data: '&pk=' + $(this).attr('data-pk') + '&name=mercredi_entree&value=' + '07:00'
			    });
			    ajaxS = $.ajax({
				type: 'post',
				url: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteStringData')) ?>',
				data: '&pk=' + $(this).attr('data-pk') + '&name=mercredi_sortie&value=' + '23:00'
			    });
			}
		    }
		});
		$('#jeudi').editable({
		    title: "Disponibilité",
		    source: [{value: 3, text: 'Non'}, {value: 1, text: 'Oui'}],
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteIntData')) ?>",
		    validate: function(value) {
			$('#data-jeudi').val(value);
			if (value == 3) {
			    $("#jeudi_entree").text("00:00");
			    $("#data-jeudi_entree").val("00:00");
			    $("#jeudi_sortie").text("00:00");
			    $("#data-jeudi_sortie").val("00:00");
			    ajaxE = $.ajax({
				type: 'post',
				url: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteStringData')) ?>',
				data: '&pk=' + $(this).attr('data-pk') + '&name=jeudi_entree&value=' + '00:00'
			    });
			    ajaxS = $.ajax({
				type: 'post',
				url: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteStringData')) ?>',
				data: '&pk=' + $(this).attr('data-pk') + '&name=jeudi_sortie&value=' + '00:00'
			    });
			}else{
			    $("#jeudi_entree").text("07:00");
			    $("#data-jeudi_entree").val("07:00");
			    $("#jeudi_sortie").text("23:00");
			    $("#data-jeudi_sortie").val("23:00");
			    ajaxE = $.ajax({
				type: 'post',
				url: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteStringData')) ?>',
				data: '&pk=' + $(this).attr('data-pk') + '&name=jeudi_entree&value=' + '07:00'
			    });
			    ajaxS = $.ajax({
				type: 'post',
				url: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteStringData')) ?>',
				data: '&pk=' + $(this).attr('data-pk') + '&name=jeudi_sortie&value=' + '23:00'
			    });
			}
		    }
		});
		$('#vendredi').editable({
		    title: "Disponibilité",
		    source: [{value: 3, text: 'Non'}, {value: 1, text: 'Oui'}],
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteIntData')) ?>",
		    validate: function(value) {
			$('#data-vendredi').val(value);
			if (value == 3) {
			    $("#vendredi_entree").text("00:00");
			    $("#data-vendredi_entree").val("00:00");
			    $("#vendredi_sortie").text("00:00");
			    $("#data-vendredi_sortie").val("00:00");
			    ajaxE = $.ajax({
				type: 'post',
				url: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteStringData')) ?>',
				data: '&pk=' + $(this).attr('data-pk') + '&name=vendredi_entree&value=' + '00:00'
			    });
			    ajaxS = $.ajax({
				type: 'post',
				url: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteStringData')) ?>',
				data: '&pk=' + $(this).attr('data-pk') + '&name=vendredi_sortie&value=' + '00:00'
			    });
			}else{
			    $("#vendredi_entree").text("07:00");
			    $("#data-vendredi_entree").val("07:00");
			    $("#vendredi_sortie").text("23:00");
			    $("#data-vendredi_sortie").val("23:00");
			    ajaxE = $.ajax({
				type: 'post',
				url: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteStringData')) ?>',
				data: '&pk=' + $(this).attr('data-pk') + '&name=vendredi_entree&value=' + '07:00'
			    });
			    ajaxS = $.ajax({
				type: 'post',
				url: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteStringData')) ?>',
				data: '&pk=' + $(this).attr('data-pk') + '&name=vendredi_sortie&value=' + '23:00'
			    });
			}
		    }
		});
		$('#samedi').editable({
		    title: "Disponibilité",
		    source: [{value: 3, text: 'Non'}, {value: 1, text: 'Oui'}],
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteIntData')) ?>",
		    validate: function(value) {
			$('#data-samedi').val(value);
			if (value == 3) {
			    $("#samedi_entree").text("00:00");
			    $("#data-samedi_entree").val("00:00");
			    $("#samedi_sortie").text("00:00");
			    $("#data-samedi_sortie").val("00:00");
			    ajaxE = $.ajax({
				type: 'post',
				url: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteStringData')) ?>',
				data: '&pk=' + $(this).attr('data-pk') + '&name=samedi_entree&value=' + '00:00'
			    });
			    ajaxS = $.ajax({
				type: 'post',
				url: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteStringData')) ?>',
				data: '&pk=' + $(this).attr('data-pk') + '&name=samedi_sortie&value=' + '00:00'
			    });
			}else{
			    $("#samedi_entree").text("07:00");
			    $("#data-samedi_entree").val("07:00");
			    $("#samedi_sortie").text("23:00");
			    $("#data-samedi_sortie").val("23:00");
			    ajaxE = $.ajax({
				type: 'post',
				url: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteStringData')) ?>',
				data: '&pk=' + $(this).attr('data-pk') + '&name=samedi_entree&value=' + '07:00'
			    });
			    ajaxS = $.ajax({
				type: 'post',
				url: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveDisponibiliteStringData')) ?>',
				data: '&pk=' + $(this).attr('data-pk') + '&name=samedi_sortie&value=' + '23:00'
			    });
			}
		    }
		});

		// Ajouter un Diplome
		$('.add-diplome').click(function(e) {
		    e.preventDefault();
		    ajax = $.ajax({
			type: 'post',
			url: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'selectDiplome')) ?>',
			data: '&matricule=<?php echo $employe->matricule; ?>'
		    });
		    ajax.done(function(data) {
			$('#dialog1').hide().html(data).fadeIn('fast').dialog({
			    width: 480,
			    height: 340,
			    title: "Sélection des Diplômes",
			    autoOpen: true,
			    modal: true,
			    show: {effect: 'fade', duration: 500},
			    hide: {effect: 'fade', duration: 250},
			    draggable: false
			});
		    });
		    ajax.fail(function() {
			showError("Une erreur est survenue lors du chargement des diplômes !");
		    });
		});
		// Ajouter un Formation
		$('.add-formation').click(function(e) {
		    e.preventDefault();
		    ajax = $.ajax({
			type: 'post',
			url: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'selectFormation')) ?>',
			data: '&matricule=<?php echo $employe->matricule; ?>'
		    });
		    ajax.done(function(data) {
			$('#dialog1').hide().html(data).fadeIn('fast').dialog({
			    width: 480,
			    height: 340,
			    title: "Sélection des Formations",
			    autoOpen: true,
			    modal: true,
			    show: {effect: 'fade', duration: 500},
			    hide: {effect: 'fade', duration: 250},
			    draggable: false
			});
		    });
		    ajax.fail(function() {
			showError("Une erreur est survenue lors du chargement des formations !");
		    });
		});
		
		// CV
		$('#cv_path').click(function(e) {
		    // Ouverture de la boite de dialogue
		    e.preventDefault();
		    ajax = $.ajax({
			type: 'post',
			url: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'dialogUpload')) ?>',
			data: '&matricule=<?php echo $employe->matricule; ?>'
		    });
		    ajax.done(function(data) {
			$('#dialog1').hide().html(data).dialog({
			    title: 'Upload de Fichier PDF',
			    width: 600,
			    height: 400,
			    autoOpen: true,
			    modal: true,
			    draggable: false,
			});
		    });
		});

		// Entretien Individuel
		$('#entretien').editable({
		    title: "Date de l'entretien individuel",
		    format: 'DD/MM/YYYY',
		    template: 'D / MMMM / YYYY',
		    placement: 'left',
		    url: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeEntretienData')) ?>',
		    params: function(params) {
			value = params.value;
			date = moment(value, ['YYYY-MM-DD', 'DD/MM/YYYY']);
			params.value = date.format('YYYY-MM-DD');
			return params;
		    }
		});

		// Au click select
		$('.clickSelect').click(function() {
		    this.select();
		});

		// RHDateTime
		$('.rhdatetime').each(function() {
		    text = $(this).text();
		    result = isValideDateRH(text);
		    if (!result) {
			$(this).text("Aucun");
		    }
		});

		// Effacer les dates
		$('.cancel-date').click(function(e) {
		    e.preventDefault();
		    if (!confirm("Voulez-vous effacer la date ?")) {
			return false;
		    }
		    id = $(this).attr('data-id');
		    name = $(this).attr('data-name');
		    value = '0000-00-00';
		    table = $(this).attr('data-table');
		    pk = $(this).attr('data-pk');
		    ajax = $.ajax({
			type: 'post',
			url: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'cancelDate')) ?>',
			data: '&id=' + id + '&pk=' + pk + '&name=' + name + '&value=' + value + '&table=' + table
		    });
		    ajax.done(function(result) {
			if (result.done) {
			    $('#' + id).text("Aucun");
			} else {
			    // $('#' + id).text('ERREUR');
			    // showError("Erreur");
			}
		    });
		});

		// Ajout Contrat
                <?php if ($isCdiAndHasDateDepart) :?>
                    $('.contrat-add').click(function(e) {
                        e.preventDefault();
                        showError('Il n\'est plus possible d\'ajouter un contrat !');
                    });
                <?php else :?>
                    $('.contrat-add').click(function(e) {
                        e.preventDefault();
                        matricule = $(this).attr('data-matricule');
                        ajax = $.ajax({
                            type: 'post',
                            url: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'showContratMenu')) ?>',
                            data: '&matricule=' + matricule
                        });
                        ajax.done(function(data) {
                            $('#dialog-contrat').hide().html(data).show('normal');
                        });
                    });
                <?php endif ;?>

		// Effacer un diplome
		$('.cancel-diplome').click(function(e) {
		    e.preventDefault();
		    pk = $(this).attr('data-pk');
		    deleteSomething('<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'deleteDiplome')) ?>', pk, "Voulez-vous effacer le diplome ?", 'd');
		});

		// Effacer une formation
		$('.cancel-formation').click(function(e) {
		    e.preventDefault();
		    pk = $(this).attr('data-pk');
		    deleteSomething('<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'deleteFormation')) ?>', pk, "Voulez-vous effacer la formation ?", 'f');
		});

		// Changer Photo
		$('#photo-upload').click(function(e){
		    e.preventDefault();
		    uploadWindow = window.open('<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'uploadPhoto', 'id'		 => $employe->matricule)) ?>', 'UploadWindow', 'menubar=no, scrollbars=no, top=100, left=100, width=500, height=400');
		});
                $('#btn-uploadPhoto').on('click', function(e){ //simulate click in #photo-upload'
                    e.preventDefault();
                    $('#photo-upload').click();
                })
                $('#btn-uploadPhoto-cntr').hover(function(e){                    
                     $('#btn-uploadPhoto').css('display', '');
                }).mouseleave(function(e){                    
                     $('#btn-uploadPhoto').css('display', 'none');
                });
                 
                              
                $('#rib_iban').editable({
		    title: "IBAN",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>",
		    validate: function(value) {
			rib_iban = value;
			
		    },
		    inputclass: 'x-largeinput'
		});
                $('#rib_bic').editable({
		    title: "BIC",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>",
		    validate: function(value) {
			rib_bic = value;
			
		    },
		    inputclass: 'x-largeinput'
		});
              
		// changer de site
		$('#changeSite').click(function(e){
		    e.preventDefault();
		    $ajax = $.ajax({
			type: 'post',
			url : '<?php echo $this->url('RHX/default', array('controller' => 'employe', 'action' => 'changeSite')) ?>',
			data: '&matricule=<?php echo $employe->matricule; ?>&site=<?php echo $employe->getSite()->id; ?>'
		    });
		    $ajax.done(function(result){
			showInfo(result, 'Changement de Site');
		    });
		    $ajax.fail(function(){
			showError("Une erreur est survenue !");
		    });
		});
                
                //annuler tranfert du site 
                $('#cancelChangeSite').on('click', function(e){
                    e.preventDefault();
                    $bool =  confirm('Voulez-vous annuler le transfert ?');
                    
                    if( !$bool ){
                        return false;
                    }
                    
                    $aj = $.ajax({
			type: 'post',
			url : '<?php echo $this->url('RHX/default', array('controller' => 'employe', 'action' => 'cancelTransfert')) ?>',
			data: '&matricule=<?php echo $employe->matricule; ?>&site=<?php echo $employe->getSite()->id; ?>'
		    });
		    $aj.done(function(result){
			window.location.reload();
		    });
		    $aj.fail(function(){
			showError("Une erreur est survenue !");
		    });
                });
                
                // UPLOAD FILE
		<?php $flags = array(FileManager::EMPLOYE_RIB_FILE , FileManager::EMPLOYE_CONTRAT_FILE ,  FileManager::EMPLOYE_SEJOUR_NUM_FILE , FileManager::EMPLOYE_CV_FILE, FileManager::EMPLOYE_AVENANT_FILE); ?>
                <?php  foreach ($flags as $flagFile) : ?> 
                     
                     $("#<?php echo $flagFile;?>-upload").on('click', function(e){
                        <?php $sPattern = '__0'?>    
                                
                        var url_motif = '<?php echo $this->url('RHX/default', array('controller'	 => 'file', 'action'	 => 'upload', 'id' => $sPattern)) ;?>?flag=<?php echo $flagFile ;?>',
                            $this = $(this);
                        
                        e.preventDefault();
                        url = url_motif.replace('<?php  echo $sPattern ;?>', $this.data('id')) ;                        
                        uploadWindow = window.open(url, 'UploadWindow', 'menubar=no, scrollbars=no, top=100, left=100, width=500, height=400');		
                });
                <?php endforeach; ?>
                
                // adding upload                
                $("#<?php echo $flagFile;?>-upload-adding").on('click', function(e){
                        <?php $sPattern = '__0'?>    
                                
                        var url_motif = '<?php echo $this->url('RHX/default', array('controller'	 => 'file', 'action'	 => 'upload', 'id' => $sPattern)) ;?>?flag=<?php echo $flagFile ;?>',
                            $this = $(this);
                        
                        e.preventDefault();
                        url = url_motif.replace('<?php  echo $sPattern ;?>', $this.data('id')) ;                        
                        uploadWindow = window.open(url, 'UploadWindow', 'menubar=no, scrollbars=no, top=100, left=100, width=500, height=400');		
                });
                
                $('#avenantRemoveButton').on('click', function(e){                    
                    e.preventDefault();
                    var $thisBtn = $(this),
                        id_av = $thisBtn.data('pk'), 
                        id_emp = $thisBtn.data('pk_employe');
                    
                    conf = confirm("Voulez-vous supprimer l'avenant en cours? ");
                    if(!conf){
                        return false;
                    }
                        
                    $aj = $.ajax({
                            type: 'POST',
                            url : '<?php echo $this->url('RHX/default', array('controller' => 'employe', 'action' => 'removeAvenant')) ?>',
                            data : '&id='+ id_av+ '&id_emp='+ id_emp,
                            });
                    $aj.done(function(data){
                        if(data && data.success){
                            console.log('success');
                            window.location.reload();
                        }
                        else{
                            showError(data && data.info ? data.info : 'Erreur Serveur');
                        }
                    });
                    $aj.fail(function(data){
                        showError('Erreur Serveur');
                    });
                    
                });
                
	    });

	    /**
	     * Effacer un Truc

	     * @param {type} url
	     * @param {type} pk
	     * @param {type} title
	     * @param {type} prefix
	     * @returns {Boolean} */
	    function deleteSomething(url, pk, title, prefix) {
		if (!url)
		    return false;
		if (!pk)
		    return false;
		if (!title)
		    title = "Voulez-vous effacer ?";
		if (!prefix)
		    prefix = '';
		if (!confirm(title))
		    return false;
		ajax = $.ajax({
		    type: 'post',
		    url: url,
		    data: '&id=' + pk
		});
		ajax.done(function(result) {
		    if (result.done) {
			//showError("#" + prefix + pk);
			$('#' + prefix + pk).parent().hide('normal');
		    }
		});

		return false;
	    }

	    function isValidDate(d) {
		var dateRegEx = /^((((0?[1-9]|[12]\d|3[01])[\.\-\/](0?[13578]|1[02])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|[12]\d|30)[\.\-\/](0?[13456789]|1[012])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|1\d|2[0-8])[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|(29[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00)))|(((0[1-9]|[12]\d|3[01])(0[13578]|1[02])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|[12]\d|30)(0[13456789]|1[012])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|1\d|2[0-8])02((1[6-9]|[2-9]\d)?\d{2}))|(2902((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00))))$/;
		return d.match(dateRegEx);
	    }

	    function isValideDateRH(d) {
		length = d.length;
		if (length > 10) {
		    return false;
		}
		return true;
	    }

	    function save()
	    {
		date_naissance = $("#date_naissance").val();
		date_fin_validite_sejour = $("#date_fin_validite_sejour").val();
		date_effet = $("#date_effet").val();

		var data = $('#formData').serialize();
		//data += "&date_naissance=" + date_naissance + "&date_effet=" + date_effet + "&date_fin_sejour=" + date_fin_validite_sejour;
		var ajax = $.ajax({
		    type: 'post',
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveedit', 'id'		 => $employe->matricule)) ?>",
		    data: data
		});
		ajax.success(function() {
		    location.href = "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'index', 'id'		 => $employe->site_id)) ?>";
		});
		ajax.error(function() {
		    showError("Une erreur est survenue");
		});
	    }

	    function dump(obj) {
		var out = '';
		for (var i in obj) {
		    out += i + ": " + obj[i] + "\n";
		}

		showError(out);
	    }
            
            <?php if ( ! ($isCDI && !$isActive)) : ?> <?php // js lorsque contrat cdi - fermé ?> 
                    function addAvenant()
                    {
                        // Ask if the user really want to create new Avenant
                        var conf = confirm("Voulez-vous créer un nouvel Avenant ?");
                        if (!conf)
                            return false;
                        // New Amendemnt
                        $('#new-avenant').val(1);
                        var annuler = "Cliquer ici pour <a href='#' onclick='return cancelNewAvenant();'>Annuler et revenir à la liste des employés du Site <b><?php echo $site->libelle ?></b></a>";
                        $('#avenant-message').show('slow').html("<span>Un nouvel avenant sera créer à l'enregistrement des informations en cours</span>. " + annuler);
			$('#avenantCancelButton').show('normal');

                        // Masquage des Edition, Affichage des Nouveaux
                        $('#posteEdit').hide('normal', function() {
                            $('#posteNew').show('normal');
                            // Rendre éditable
                            $('#posteNeo').editable({
                                title: "Edition du Nouveau Poste",
                                source: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'jsonpostelist')) ?>",
                                validate: function(value) {
                                    $("#data-poste").val(value);
                                    //$("#data-poste_id").val(value);
                                    poste = value;
                                    ajax = $.ajax({
                                        type: 'post',
                                        url: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'getPosteInfo')) ?>',
                                        data: '&id=' + poste
                                    });
                                    ajax.done(function(result) {
                                        info = result.info;
                                        $('#collegeNeo').text(info.college);
                                        $('#niveauNeo').text(info.niveau);
                                        $('#echelonNeo').text(info.echelon);
                                        // changement des données
                                        $('#data-niveau').val(info.niveau_value);
                                        $('#data-echelon').val(info.echelon_value);
                                        $('#data-college').val(info.college_value);
                                    });
                                }
                            });
                        });
                        $('#niveauNeo').editable({
                            title: "Edition du NIveau",
                            source: '<?php echo json_encode($niveau); ?>',
                            validate: function(value) {
                                $('#data-niveau').val(value);
                            }
                        });
                        $('#echelonNeo').editable({
                            title: "Edition de l'échelon",
                            source: '<?php echo json_encode($echelon); ?>',
                            validate: function(value) {
                                $('#data-echelon').val(value);
                            }
                        });
                        $("#collegeNeo").editable({
                            title: "Edition du collège",
                            source: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'collegeList')); ?>",
                            validate: function(value) {
                                $('#data-college').val(value);
                            }
                        });
                        $('#avenantEdit').hide('normal', function() {
                            $('#avenantNew').show('normal');
                            // Rendre éditable
                            $('#hebdo').editable({
                                title: "Modification de l'Heure Hedbomadaire",
                                validate: function(value) {
                                    $('#data-hebdo').val(value);
                                },
                                inputclass: 'clickSelect',
                                tpl: '<input type="text" onclick="select();" onmouseover="select();">'
                            });
                            $('#taux').editable({
                                title: "Modification du Taux Horaire",
                                validate: function(value) {
                                    $('#data-taux').val(value);
                                },
                                inputclass: 'clickSelect',
                                tpl: '<input type="text" onclick="select();" onmouseover="select();">'
                            });
                            $('#debut').editable({
                                title: "Date de Début de l'Avenant",
                                format: 'DD/MM/YYYY',
                                template: 'D / MMMM / YYYY',
                                placement: 'left',
                                //url : "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>",
                                validate: function(value) {
                                    var val = value.year() + '-' + (parseInt(value.month()) + 1) + '-' + value.date();
                                    $('#data-debut').val(val);
                                },
                                params: function(params) {
                                    value = params.value;
                                    date = moment(value, ['YYYY-MM-DD', 'DD/MM/YYYY']);
                                    params.value = date.format('YYYY-MM-DD');
                                    return params;
                                },
				combodate: {
				    minYear: 2000,
				    maxYear: 2025,
				    minuteStep: 1
				}
                            });
                            $('#fin').editable({
                                title: "Date de Fin de l'Avenant",
                                format: 'DD/MM/YYYY',
                                template: 'D / MMMM / YYYY',
                                placement: 'left',
                                //url : "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveEmployeStringData')) ?>",
                                validate: function(value) {
                                    var val = value.year() + '-' + (parseInt(value.month()) + 1) + '-' + value.date();
                                    $('#data-fin').val(val);
                                },
                                params: function(params) {
                                    value = params.value;
                                    date = moment(value, ['YYYY-MM-DD', 'DD/MM/YYYY']);
                                    params.value = date.format('YYYY-MM-DD');
                                    return params;
                                }
                            });
                        });
                        $('#save-planning').click(function(e) {
                            e.preventDefault();
                            return AddNewAvenant();
                        });
                        // Bouton d'ajout
                        //$('#avenantAddButton').show(1000);
                        $('#save-planning').show('slow');
                        // Masquage des boutons
                        $('#avenantNewButton').hide('normal');
                        $('#avenantEditButton').hide('normal');
                        // Changement de couleur
                        $('.empl-saumon').removeClass('empl-saumon').addClass('saumon');
                        $('.empl-jaune').removeClass('empl-jaune').addClass('jaune');
                        $('.empl-gris').removeClass('empl-gris').addClass('gris');

                        return false;
                    }
            <?php endif; ?>
	    function cancelNewAvenant()
	    {
		$('#new-avenant').val(0);
		$('#avenant-message').html('<span></span>');

		return false;
	    }

	    function avenantHistory(employeId)
	    {
		var url = "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'avenant')) ?>/" + employeId;
		var ajax = $.ajax({
		    type: 'post',
		    url: url
		});
		ajax.success(function(data) {
		    $('#avenant-dialog').html(data).dialog({
			title: "Historique des avenants pour <?php echo addslashes($name) ?>",
			width: 800,
			height: 600,
			autoOpen: true,
			modal: true,
			show: {effect: 'fade', duration: 700},
			hide: {effect: 'fade', duration: 700},
			draggable: false
		    });
		});
		ajax.error(function() {
		    showError("Ne peut pas afficher l'historique");
		});

		return false;
	    }

	    function avenantDetails(avenantId, title)
	    {
		var url = "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'avenantdetails')) ?>/" + avenantId;
		var ajax = $.ajax({
		    type: 'post',
		    url: url,
		    data: '&title=' + encodeURI(title)
		});
		ajax.success(function(data) {
		    $('#avenant-dialog').html(data).dialog({
			title: title,
			width: 480,
			height: 480,
			autoOpen: true,
			modal: true,
			show: {effect: 'fade', duration: 700},
			hide: {effect: 'fade', duration: 700},
			draggable: false
		    });
		});
		ajax.error(function() {
		    showError("Ne peut pas afficher l'historique");
		});

		return false;
	    }

	    function editAvenant()
	    {
		// It makes the avenant fields editable
		var conf = confirm("Voulez-vous Editer l'Avenant en cours ?");
		if (conf != true)
		    return false;

		makeEditable();

		return false;
	    }
            

	    function makeEditable() {
		//showError('Make editable');
		// Changement de couleur
		$('.empl-saumon').removeClass('empl-saumon').addClass('saumon');
		$('.empl-jaune').removeClass('empl-jaune').addClass('jaune');
		$('.empl-gris').removeClass('empl-gris').addClass('gris');
		// Highlight
		setTimeout(function() {
		    $('.empl-highlight').effect('highlight', 'slow');
		}, 1000);
		// Masquage des Boutons
		//$('#avenantNewButton').hide('normal');
		$('#avenantEditButton').hide('normal');
                
                // btn upload avenant
                $('#<?php echo FileManager::EMPLOYE_AVENANT_FILE;?>-upload').show('normal');
                $('#<?php echo FileManager::EMPLOYE_AVENANT_FILE  ; ?>-info-hasFile').hide();
                
		// Affichage du Nom de l'avenant
		$('#avenant-name').hide().html($('#av-<?php echo $avenant->id; ?>').text()).fadeIn('normal');
		if ($('#av-<?php echo $avenant->id; ?>').length === 0) {
		    $('#avenant-name').hide().html("Contrat").fadeIn('normal');
		}

		$('#poste').editable({
		    title: 'Poste',
		    source: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'jsonpostelist')) ?>",
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveAvenantIntData')); ?>",
		    validate: function(value) {
			poste = value;
			$('#data-poste_id').val(value);
			ajax = $.ajax({
			    type: 'post',
			    url: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'getPosteInfo')) ?>',
			    data: '&id=' + poste
			});
			ajax.done(function(result) {
			    info = result.info;
			    $('#college').text(info.college);
			    $('#niveau').text(info.niveau);
			    $('#echelon').text(info.echelon);
			    // changement des données
			    pkAvenant = $('#niveau').attr('data-pk');
			    ajaxCollege = $.ajax({
				type: 'post',
				url: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveAvenantIntData')); ?>',
				data: '&pk=' + pkAvenant + '&name=college&value=' + info.college_value
			    });
			    ajaxNiveau = $.ajax({
				type: 'post',
				url: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveAvenantIntData')); ?>',
				data: '&pk=' + pkAvenant + '&name=niveau&value=' + info.niveau_value
			    });
			    ajaxEchelon = $.ajax({
				type: 'post',
				url: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveAvenantIntData')); ?>',
				data: '&pk=' + pkAvenant + '&name=echelon&value=' + info.echelon_value
			    });
			});
		    }
		});
		$('#niveau').editable({
		    title: 'Niveau',
		    source: '<?php echo json_encode($niveau); ?>',
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveAvenantIntData')); ?>"
		});
		$('#echelon').editable({
		    title: 'Echelon',
		    source: '<?php echo json_encode($echelon); ?>',
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveAvenantIntData')); ?>"
		});
		$('#college').editable({
		    title: 'Collège',
		    source: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'collegeList')); ?>',
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveAvenantIntData')); ?>"
		});
		$('#horaire_hebdo').editable({
		    title: 'Horaire Hebdomadaire',
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveAvenantIntData')); ?>",
		    validate: function(value) {
			horaire_hebdo = value;
			$('#data-horaire_hebdo').val(value);
		    },
                    tpl: "<input type='text' onKeyPress='validateNumber(event);' onclick='select();' onmouseover='select();'>",
		    inputclass: 'clickSelect',
		    /*tpl: '<input type="text" onclick="select();" onmouseover="select();">'*/
		});
		$('#horaire_taux').editable({
		    title: 'Taux Horaire',
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveAvenantIntData')); ?>",
		    validate: function(value) {
			horaire_taux = value;
			$('#data-horaire_taux').val(value);
		    },
                    tpl: "<input type='text' onKeyPress='validateNumber(event);' onclick='select();' onmouseover='select();'>",
		    inputclass: 'clickSelect',
		    /*tpl: '<input type="text" onclick="select();" onmouseover="select();">'*/
		});
                /*
		$('#avenant_debut').editable({
		    title: "Date de début de l'Avenant",
		    format: 'DD/MM/YYYY',
		    template: 'D / MMMM / YYYY',
		    placement: 'left',
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveAvenantStringData')); ?>",
		    validate: function(value) {
			var val = value.year() + '-' + (parseInt(value.month()) + 1) + '-' + value.date();
			
                        $('#data-debut_avenant').val(val);                            
		    },
		    params: function(params) {
			value = params.value;
			date = moment(value, ['YYYY-MM-DD', 'DD/MM/YYYY']);
			params.value = date.format('YYYY-MM-DD');
			return params;
		    },
		    combodate: {
			minYear: 1950,
			maxYear: 2025,
			minuteStep: 1
		    }
		}); 
                */
                $('#avenant_debut').editable({
		    title: "Date de début de l'Avenant",
		    source : "<?php echo $this->url('RHX/default', array('controller'	 => 'periode', 'action'	 => 'jsonFirstFuturMonth')) ?>",
		    placement: 'left',                    
		    validate: function(value) {
                        var $this = $('#avenant_debut');
                        
                        $this.fadeOut();
                        param = {
                            pk: $this.attr('data-pk'),
                            name:  $this.attr('data-name'),
                            value: value
                        };
                       
                        JsEmpEidt.update_editable({                                
                                url : "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveAvenantStringDataDate')); ?>",
                                param : param,
                                success: function(data){                                    
                                    if(data.success){                                        
                                        dateHTML = data.date_html;                                        
                                        
                                        $('#data-debut_avenant').val(value);
                                        //$this.css('diplay', 'none');
                                        $this.fadeOut();
                                        setTimeout(function(){
                                            $this.text(dateHTML).fadeIn();
                                        },200);
                                    }
                                }
                            }); 
                      $this.css('diplay', ''); 
		    }
		});
		$('#avenant_fin').editable({
		    title: "Date de fin de l'Avenant",
		    format: 'DD/MM/YYYY',
		    template: 'D / MMMM / YYYY',
		    placement: 'left',
		    url: "<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'saveAvenantStringData')); ?>",
		    validate: function(value) {
			var val = value.year() + '-' + (parseInt(value.month()) + 1) + '-' + value.date();
			$('#data-fin_avenant').val(val);
		    },
		    params: function(params) {
			value = params.value;
			date = moment(value, ['YYYY-MM-DD', 'DD/MM/YYYY']);
			params.value = date.format('YYYY-MM-DD');
			return params;
		    },
		    combodate: {
			minYear: 1950,
			maxYear: 2025,
			minuteStep: 1
		    }
		});
	    }

	    function AddNewAvenant() {
		ajax = $.ajax({
		    type: 'post',
		    url: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'addNewAvenant')) ?>',
		    data: $('#avenantNewForm').serialize()
		});
		ajax.success(function() {
		    location.reload();
		});
		ajax.error(function() {
		    showError("Erreur");
		});
	    }

	    function cancelAvenantChange() {
		window.location.reload();
		// On remet le tout à l'état initial
		$('#posteEdit .saumon').removeClass('saumon').addClass('empl-saumon');
		$('#avenantEdit .jaune').removeClass('jaune').addClass('empl-jaune');
		$('#avenantEdit .gris').removeClass('gris').addClass('empl-gris');

		$('#poste').editable('toggleDisabled');
		$('#horaire_hebdo').editable('toggleDisabled');
		$('#horaire_taux').editable('toggleDisabled');
		$('#avenant_debut').editable('toggleDisabled');
		$('#avenant_fin').editable('toggleDisabled');

		$('#posteEdit').show('fast');
		$('#avenantEdit').show('fast');

		$('#posteNew').hide();
		$('#avenantNew').hide();

		$('#avenantAddButton').hide();

		// Affichage des 2 boutons d'ajout et d'édition
		$('#avenantNewButton').show('normal');
		$('#avenantEditButton').show('normal');

		// Masquage du Nom de
		$('#avenant-name').hide('normal');

		return false;
	    }

	    function toTitleCase(str) {
		return str.replace(/\w\S*/g, function(txt) {
		    return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
		});
	    }
	    
	    /**
	    * Mise à jour de tous les plannings types
            * @param object paramCall  : onSuccess est le callback à appelé au succès de l'update
	     */
	    function updateAllPlanningType(paramCall){                
                var defautsParam =  { "onSuccess" : null };
                
                param = $.extend(defautsParam, paramCall);
                
		$ajax = $.ajax({
		    type: 'post',
		    url : '<?php echo $this->url('RHX/default', array('controller' => 'template', 'action' => 'updatePlanningTemplate')) ?>'
		});
                
                $ajax.success(function(data){
                    if (param.onSuccess)
                        param.onSuccess(data);                 
                });
	    }
            
            /**
	    * Mise à jour de tous les plannings semaine
	     */
	    function updateAllPlanningSemaine(){                
                ajax = $.ajax({
		    type: 'post',
		    url : '<?php echo $this->url('RHX/default', array('controller' => 'planning', 'action' => 'updatePlanningSemaine')) ?>',
                    data : "&matricule=<?php echo $employe->matricule; ?>",
                    success : function(data){
                        //console.log(data.info);
                    }
		});
                
	    }
            
   var JsEmpEidt = (function(){
        var isEmpty = function(selector){
                return $.trim($(selector).val()) === '';
            },
            isFloat = function(val){
                v = $.trim(val);
                patFloat = new RegExp(/^[0-9]*[.]{0,1}[0-9]+$/);

                return patFloat.test(v);                     
            }
            ;
            
        return {
            init : function(){               
            }, 
            update_editable : function(objCall){
                            var objDef = { "url": null, "param": null, 'success' : null};
                            obj = $.extend(objDef , objCall) ;
                            if( ! (obj.url && obj.param) )
                                return false;
                            
                            var url    = obj.url,
                                param  = obj.param;                              
                            
                            data = 'pk='+param.pk+ '&name='+param.name+'&value=' + param.value;
                            
                            $ajax = $.ajax({ type: 'post', url: url, data: data, async: false }); 
                            $ajax.success(function(ajaxData){
                                console.log(ajaxData);
                                if(obj.success){
                                    obj.success(ajaxData);
                                }
                            });
                          } 
        } 
    } )(); 
   
</script>
<script type="text/javascript">
    $(function(){
	$('#doc-printer').click(function(e){
	    e.preventDefault();
	    $ajax = $.ajax({
		type: 'post',
		url : '<?php echo $this->url('RHX/default', array('controller' => 'employe', 'action' => 'printContrat')) ?>',
		data: '&matricule=<?php echo $employe->matricule; ?>'
	    });
	    $ajax.done(function(result){});
	});
    });
</script>
<style type="text/css">
    #nom, #nom2{
	text-transform: uppercase;
    }
    .uppercase{
	text-transform: uppercase;
    }
    .capitalize{
	text-transform: capitalize;
    }
    .cancel-icon{
	position: absolute;
	top: 1px;
	right: 4px;
    }
    .add-contrat{
	position: absolute;
	right: 16px;
	top: 25px;
	width: 650px;
	min-height: 100px;
	background: #fff;
	z-index: 99;
	border-radius: 10px 0px 10px 10px;
	box-shadow: 0px 3px 5px 2px #a7a7a7;
	border: solid 1px #707070;
	padding: 10px;
    }
    .spn2{
	margin-left: 1px;
	width: 15%;
    }
    .spn1{
	margin-left: 1px;
	width: 7%; 
    }
    
     .empl-title .employe-info-tranfert{
        color: #FFFFFF;
        display: block;
        float: right;
        margin-right: 10px;
        text-shadow: 2px 1px #222222;
        text-transform: none;
    }
</style>